我正在向在線交易REST API發出OAuth 1.0a請求。據我所知,下面的代碼是提出請求的方式,但我在request.ContentLength = postData.Length;
行上得到了「此屬性無法在寫入啓動後設置」消息......我不明白爲什麼。如果這不是將POST數據添加到經過OAuth身份驗證的Web請求發出之前的方式,那麼是什麼?寫作開始後,無法設置此屬性...我什麼時候開始寫作?
var request = consumer.PrepareAuthorizedRequest(new DotNetOpenAuth.Messaging.MessageReceivingEndpoint(new Uri(this.EndPointAddress, relativeUri), method), this.AccessToken);
request.Method = (method == DotNetOpenAuth.Messaging.HttpDeliveryMethods.PostRequest) ? "POST" : "GET";
if (postValues != null && postValues.Count > 0)
{
//There is POST data associated with this request, include it
var postData = KVPCollectionToString(postValues);
request.ServicePoint.Expect100Continue = false;
request.ContentLength = postData.Length;
Logger.Trace(t => t("POST Data: {0}", postData));
using (var stream = request.GetRequestStream())
{
var pBytes = System.Text.Encoding.UTF8.GetBytes(postData);
stream.Write(pBytes, 0, pBytes.Length);
}
}
這是知道的好信息!修改我的代碼以發送我的POST值的IDictionary'成功創建了請求。當然,它失敗了一些通用的'signature_method_rejected'問題,但這是另一個問題。謝謝! –
2013-02-22 01:54:19