在windowsphone 8中获取请求流



我想使用MSDN代码通过HttpWebRequest发布数据,但getresponse()不起作用。

System.net.httpwebrequest does not contain a definition for getrequeststream

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx

 using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
 HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://d.co/login.php");
 myReq.Method = "POST";
 myReq.ContentType = "application/json";
 Stream dataStream = (HttpWebResponse)myReq.GetRequestStream();

该方法在Windows Phone上不存在,因为有很多人经常使用异步IO。您需要GetRequestStreamAsyncBeginGetRequestStream*Async方法通常比Begin*更容易理解和使用,但需要最新的编译器。相关的示例在这里,在基于电话的文档中:http://msdn.microsoft.com/en-us/library/windowsphone/develop/System.Net.HttpWebRequest(v=vs.105).aspx

最新更新