2010-08-25 76 views
2

我想发布到谷歌,所以我可以登录到谷歌阅读器和下载订阅列表,但我无法找到一种方式发布到谷歌在Windows 7手机sdk,没有人有一个例子这个怎么做?Post with WebRequest

*编辑:对不起并不是很清楚我正在尝试使用POST方法,将电子邮件和密码提交给Google登录并检索sid。我已经使用WebClient和HttpWebRequest,但所有的例子,我已经看到发送数据,API调用不在Windows 7手机SDK。

回答

3

您是否尝试过为您的Windows Phone 7项目使用RESTSharp?最新版本支持Windows Phone 7,并且我没有与流行的REST API一起使用它的问题。在您尝试使用Google Reader API的特定情况下,Luke Lowry的this article可能会有所帮助。

3

不确定你已经使用了什么,但你有没有试过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” 编辑,Web客户端让你做后:

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

你还那么必须添加一个OpenWriteCompleted处理程序。

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

+0

请参阅我的编辑 – instigator 2010-08-25 18:57:14

18

我对您尝试使用的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标头的方法。