我正在向在线交易 REST API 发出 OAuth 1.0a 请求。据我所知,以下代码是发出请求的方式,但我收到一条“此属性在写入开始后无法设置”消息request.ContentLength = postData.Length;
......我不明白为什么。如果这不是在 OAuth 验证的 Web 请求发出之前将 POST 数据添加到它的方法,那是什么?
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);
}
}