发布WebRequest

我试图发布到谷歌,所以我可以登录谷歌阅读器和下载订阅列表,但我无法找到一种方法发布谷歌在Windows 7手机sdk,有没有人有一个如何做到这一点的例子?

*编辑:对不起我不是很清楚我正在尝试使用POST方法,提交电子邮件和密码谷歌登录和检索一个sid。 我使用过WebClient和HttpWebRequest,但我看到的所有示例都发送了post数据,api调用不在windows 7 phone sdk中。

您是否尝试过将RESTSharp用于Windows Phone 7项目? 最新版本支持Windows Phone 7,我使用流行的REST API时没有遇到任何问题。 在您尝试使用Google阅读器API的特定情况下,Luke Lowry的这篇文章可能会有所帮助。

我对您尝试使用的Google API一无所知,但如果您只需要发送POST请求,那么您当然可以使用WebClientHttpWebRequest 。 使用WebClient ,您可以使用WebClient.OpenWriteAsync()WebClient.UploadStringAsync() ,文档位于: http : //msdn.microsoft.com/en-us/library/tt0f69eh%28v=VS.95%29。 ASPX

使用HttpWebRequest ,您需要将Method属性设置为"POST" 。 这是一个基本的例子:

 var request = WebRequest.Create(new Uri(/* your_google_url */)) as HttpWebRequest; request.Method = "POST"; request.BeginGetRequestStream(ar => { var requestStream = request.EndGetRequestStream(ar); using (var sw = new StreamWriter(requestStream)) { // Write the body of your request here } request.BeginGetResponse(a => { var response = request.EndGetResponse(a); var responseStream = response.GetResponseStream(); using (var sr = new StreamReader(responseStream)) { // Parse the response message here } }, null); }, null); 

WebClient类可能更容易使用,但可定制性较差。 例如,我没有看到能够将cookie附加到WebClient请求的方法,或者在使用WebClient时设置Content-Type标头的方法。

不确定你已经使用过什么,但是你尝试过WebClient吗?

 WebClient web = new WebClient(); web.DownloadStringCompleted += (s, e) => { if (e.Error == null) CodeHereToHandleSuccess(); else CodeHereToHandleError(e.Error); }; web.DownloadStringAsync(new Uri(theURLYoureTryingToUse)); 

还有WebRequest也可以查看,这可能适用于您正在做的事情。

编辑:对于您的“POST”编辑,webclient允许您发布:

  web.OpenWriteAsync(new Uri(theURLYoureTryingToUse), "POST"); 

然后,您还必须添加一个OpenWriteCompleted处理程序。

不确定你到底在做什么,所以你需要在你的问题中添加更多信息。