【问题标题】:Error in http requesthttp请求错误
【发布时间】:2012-06-29 04:17:42
【问题描述】:

我正在向 google.com 发出 http 请求。这就是我的做法:

    HttpTestWebRequest = (HttpWebRequest)System.Net.WebRequest.Create("http://www.google.com/");
    HttpTestWebRequest.Method = "GET";
    HttpTestWebRequest.BeginGetResponse(GetHttpTestResponse, HttpTestWebRequest);

...

private void GetHttpTestResponse(IAsyncResult asynchronousResult)
{
    var webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
    WebResponse response =((HttpWebRequest)asynchronousResult.AsyncState).EndGetResponse(asynchronousResult);
    ...
}

使用提琴手它给了我一个 http 302 移动状态码,但在应用程序中它会抛出一个异常并且不会重定向到网站的新位置。

任何想法为什么会发生这种情况?

更新 1

我收到了NullReferenceException

堆栈跟踪是:

在 System.Net.Browser.HttpWebRequestHelper.RemoveHttpOnlyCookies(Uri requestUri, String setCookieHeaderValue)
在 System.Net.Browser.HttpWebRequestHelper.ParseHeaders(Uri requestUri、SecurityCriticalDataForMultipleGetAndSet`1 标头、WebHeaderCollection 集合、布尔型 removeHttpOnlyCookies、HttpStatusCode& 状态、String& 状态描述)
在 System.Net.Browser.ClientHttpWebRequest.Progress(对象发送者,EventArgs e)
在 MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex,委托 handlerDelegate,对象发送者,对象 args)
在 MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

【问题讨论】:

  • 你看到了什么异常?
  • 请参阅上面的更新。谢谢!

标签: windows-phone-7 http http-status-code-302


【解决方案1】:

尝试设置HttpTestWebRequest.AllowAutoRedirect = true;

【讨论】:

    【解决方案2】:

    着陆页 (http://www.google.com) 上似乎有一些特定的 HTTP 标头(谷歌似乎发送了一些重复的 cookie 标头)导致了这种情况!其他网站/页面似乎加载正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多