Message from WebRequest

I am trying to publish on Google so that I can log into Google Reader and download the subscription list, but I cannot find a way to publish phone sdk on Google on Windows 7, does anyone have an example on how to do this? this is?

* Edit: Sorry, not really me. I am trying to use the POST method, send email and password to google login and retrieve sid. I used WebClient and HttpWebRequest, but all the examples that I saw for sending post-data api calls are not in Windows 7 phone sdk.

+2
source share
3 answers

Have you tried using RESTSharp for your Windows Phone 7 project? The latest version supports Windows Phone 7, and I had no problems using the popular REST APIs. In your particular case, when you try to use the Google Reader API,

+3
source

I don’t know anything about the Google API you are trying to use, but if you need to send a POST request, you can do it using WebClient or HttpWebRequest . Using WebClient you can use either WebClient.OpenWriteAsync() or WebClient.UploadStringAsync() , the documentation is here: http://msdn.microsoft.com/en-us/library/tt0f69eh%28v=VS.95%29. aspx

With HttpWebRequest you need to set the Method property to "POST" . Here is a basic example:

 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); 

The WebClient class may be easier to use, but less customizable. For example, I did not see the possibility of attaching cookies to WebClient requests or to the method of setting the Content-Type header when using WebClient .

+18
source

Not sure what you have already used, but have you tried WebClient?

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

There is also a WebRequest to see, too, what might work for what you do.

Edit: Regarding your POST editing, the web client allows you to post:

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

You also need to add an OpenWriteCompleted handler.

not sure exactly what you are doing, so you need to add additional information to your question.

+3
source

Source: https://habr.com/ru/post/885660/


All Articles