wp7使用POST请求Asp.net网页时,HttpWebRequest的BeginGetResponse方法抛出NotSupportException异常的解决方法
2011-11-10 08:37
1576 查看
使用情景如下:
UI线程中 { HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://www.exzample.com/exzample.aspx"); wr.Method = "POST"; // 必须要指定ContentType,否则服务器有可能返回Page Not Found wr.ContentType = "application/x-www-form-urlencoded"; wr.BeginGetRequestStream(new AsyncCallback(GetRequestStream_Completed), wr); } 工作线程中 { public void GetRequestStream_Completed(IAsyncResult ar) { HttpWebRequest wr = ar.AsyncState as HttpWebRequest; Stream s = wr.EndGetRequestStream(ar); s.Position = 0; s.Write(new Byte[]{ 1, 2, 3 }, 0, 3); // 写入需要的字节流 // 如果不调用此函数的话,下面的BeginGetResponse将抛出NotSupportException异常, // 但是在桌面版的Silvalight没有这个要求 s.Close(); wr.BeginGetResponse(new AsyncCallback(GetResponse_Completed), wr); } public void GetResponse_Completed(IAsyncResult ar) { HttpWebRequest wr = ar.AsyncState as HttpWebRequest; Stream s = wr.EndGetResponse(ar); s.Position = 0; Byte[] buffer = new Byte[s.Length]; s.Read(buffer, 0, s.Length); s.Close(); } }
相关文章推荐
- 【转】asp.net(c#)使用HttpWebRequest附加携带请求参数以post方式模拟上传大文件(以图片为例)到Web服务器端
- asp.net Chartr控件异常: System.Web.HttpException: 为 ChartImg.axd 执行子请求时出错(已解决)
- js_html_input中autocomplete="off"在chrom中失效的解决办法 使用JS模拟锚点跳转 js如何获取url参数 C#模拟httpwebrequest请求_向服务器模拟cookie发送 实习期学到的技术(一) LinqPad的变量比较功能 ASP.NET EF 使用LinqPad 快速学习Linq
- asp.net(c#)使用HttpWebRequest附加携带请求参数以post方式模拟上传大文件(以图片为例)到Web服务器端
- HttpWebRequest 下载网页Html代码 POST方式(站内使用了form方式) System.Net.WebException (417) Expectation failed
- asp.net后台导出excel的方法:使用System.Web.HttpContext.Current.Response导出excel
- ASP.NET使用HttpWebRequest读取远程网页源代码
- Asp.net错误“System.Web.HttpException: 超过了最大请求长度”解决办法
- Asp.net错误“System.Web.HttpException: 超过了最大请求长度”解决办法
- HttpWebRequest.GetResponse出异常时的解决办法
- Asp.Net Core IIS发布后PUT、DELETE请求错误405.0 - Method Not Allowed 因为使用了无效方法(HTTP 谓词)
- System.Web.HttpRequestValidationException异常的最好解决方法
- 用HttpWebRequest做POST请求时返回Http 417 错误解决方法
- 用HttpWebRequest做POST请求时返回Http 417 错误解决方法
- asp.net ajax Sys.WebForms.PageRequestManagerServerErrorException 500 解决方法
- ASP.NET使用HttpWebRequest读取远程网页源代码
- ASP.NET 4.0验证请求 System.Web.HttpRequestValidationException: A potentially dangerous Request.F
- ASP.NET 4.0验证请求 System.Web.HttpRequestValidationException: A potentially dangerous Request.F
- WP7中HttpWebRequest的使用方法之GET方式
- 【转】System.Net.HttpWebRequest请求超时的问题解决方法