我似乎无法弄清楚这一点。无论我做什么,我都会不断收到“417 期望失败”错误。我看过的所有地方都说我需要摆脱 HttpWebRequest 的 Expect 标头。ServicePointManager.Expect100Continue = false
在 Web 请求上设置静态属性或实例属性request.ServicePoint.Expect100Continue = false
永远不会摆脱标头。我必须手动将其设置为 null 才能将其删除。
无论如何,我仍然收到 417 错误。我错过了什么?
private static readonly MessageReceivingEndpoint UpdateStatusEndpoint
= new MessageReceivingEndpoint("http://twitter.com/statuses/update.xml", HttpDeliveryMethods.PostRequest);
public static XDocument UpdateStatus(ConsumerBase twitter, string accessToken, string message)
{
var data = new Dictionary<string, string>();
data.Add("status", message);
ServicePointManager.Expect100Continue = false; //Doesn't work
HttpWebRequest request = twitter.PrepareAuthorizedRequest(UpdateStatusEndpoint, accessToken, data);
request.ServicePoint.Expect100Continue = false; //setting here doesn't work either
//request.Expect is still set at this point unless I explicitly set it to null.
request.Expect = null;
var response = twitter.Channel.WebRequestHandler.GetResponse(request); //Throws exception
return XDocument.Load(XmlReader.Create(response.GetResponseReader()));
}