0

我似乎无法弄清楚这一点。无论我做什么,我都会不断收到“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()));
}
4

3 回答 3

3

DotNetOpenAuth 不直接设置或支持 except100Continue。如果 Channel 类中有一个属性会很好。

在调用“PrepareAuthorizedRequest”之前添加:

    ((HttpWebRequest)WebRequest.Create
(UpdateStatusEndpoint.Location)).ServicePoint.Expect100Continue = false;

根据调用的 URL 设置 except100Continue。因此,您可以在创建连接之前进行设置。您甚至可以在配置文件中全局设置它。

  <system.net>
    <settings>
      <servicePointManager expect100Continue="false" />
    </settings>
  </system.net>
于 2010-01-08T02:29:05.543 回答
1

将期望设置为“期望:无”..这是我的代码:

var data = new Dictionary();

data.Add("status", status);

HttpWebRequest request = twitter.PrepareAuthorizedRequest(UpdateStatusEndpoint, accessToken, data);

request.Expect = "expect:nothing";

var response = twitter.Channel.WebRequestHandler.GetResponse(request); exception return XDocument.Load(XmlReader.Create(response.GetResponseReader()));

它对我有用...

于 2009-09-10T21:04:25.693 回答
0

LinqToTwitter 是一个使用 DotNetOpenAuth 的 Twitter 客户端库。我将看到有关将消息发布示例添加到 DotNetOpenAuth 核心库以供未来版本使用。

于 2009-07-29T04:00:09.337 回答