问题描述
我似乎无法推测这一个。无论我做什么,我不断收到一个417预期失败的错误。无论我已经看了说我需要摆脱对于HttpWebRequest的期望头。设置在Web请求的静态属性 ServicePointManager.Expect100Continue = FALSE
或实例属性 request.ServicePoint.Expect100Continue = FALSE
从来没有得到的摆脱了头。我必须手动将其设置为null将其删除。
不管是什么,虽然,我仍然得到417错误。我在想什么?
私有静态只读MessageReceivingEndpoint UpdateStatusEndpoint
=新MessageReceivingEndpoint(http://twitter.com/statuses/update.xml,HttpDeliveryMethods.PostRequest);
公共静态的XDocument UpdateStatus(ConsumerBase叽叽喳喳,串accessToken,字符串消息)
{
VAR数据=新字典<字符串,字符串>();
data.Add(状态,邮件);
ServicePointManager.Expect100Continue = FALSE; //不工作
HttpWebRequest的要求=微博prepareAuthorizedRequest(UpdateStatusEndpoint,accessToken,数据)。
request.ServicePoint.Expect100Continue = FALSE; //设置在这里也不管用
//request.Expect仍定在这一点上,除非我明确地将它设置为null。
request.Expect = NULL;
VAR响应= twitter.Channel.WebRequestHandler.GetResponse(要求); //抛出异常
返回XDocument.Load(XmlReader.Create(response.GetResponseReader()));
}
DotNetOpenAuth不设置或直接支持Except100Continue。将是很好,如果有一个在通道类的属性。
您的来电'prepareAuthorizedRequest'之前,补充一点:
((HttpWebRequest的)WebRequest.Create
(UpdateStatusEndpoint.Location))ServicePoint.Expect100Continue = FALSE;
Except100Continue取决于被叫URL中设置。所以,你可以将它设置在创建连接之前。你甚至可以将它在全球范围内配置文件。
< system.net>
<设置>
< servicePointManager expect100Continue =FALSE/>
< /设置>
< /system.net>
I can't seem to figure this one out. No matter what I do, I keep getting a "417 Expectation failed" error. Everywhere I've looked says that I need to get rid of the Expect header for the HttpWebRequest. Setting the static property ServicePointManager.Expect100Continue = false
or the instance property on the web request request.ServicePoint.Expect100Continue = false
never get's rid of the header. I have to manually set it to null to remove it.
No matter what though, I STILL get the 417 error. What am I missing?
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()));
}
DotNetOpenAuth doesn't set or support Except100Continue directly. Would be nice if there is a property in the Channel class.
Add this before your call to 'PrepareAuthorizedRequest':
((HttpWebRequest)WebRequest.Create
(UpdateStatusEndpoint.Location)).ServicePoint.Expect100Continue = false;
Except100Continue is set depending on the called URL. So you can set it before the connection is created. You may even set it globally in the config file.
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
这篇关于展望试图更新微博状态时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!