在Windows Phone 8中获取getrequeststream

时间:2014-04-19 09:23:17

标签: c# .net windows-phone-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();

1 个答案:

答案 0 :(得分:2)

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