我想使用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();
答案 0 :(得分:2)
Windows Phone上不存在该方法,因为您经常使用异步IO。您需要GetRequestStreamAsync
或BeginGetRequestStream
。 *Async
方法通常比Begin*
更容易理解和使用,但需要最新的编译器。相关示例在此处,在手机中基于文档:http://msdn.microsoft.com/en-us/library/windowsphone/develop/System.Net.HttpWebRequest(v=vs.105).aspx