Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Look at the <a href="http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&amp;l=EN-US&amp;k=k%28SYSTEM.NET.HTTPWEBREQUEST%29;k%28TargetFrameworkMoniker-%22SILVERLIGHT,VERSION=V4.0%22%29;k%28DevLang-CSHARP%29&amp;rd=true" rel="nofollow noreferrer">HttpWebRequest</a> object.</p> <pre><code>public void DoWork() { var url = "http://posttestserver.com/post.php"; // Create the web request object HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; // Start the request webRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), webRequest); } void GetRequestStreamCallback(IAsyncResult asynchronousResult) { HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState; // End the stream request operation Stream postStream = webRequest.EndGetRequestStream(asynchronousResult); // Create the post data // Demo POST data string postData = "Username=MyUserName&amp;password=MyPassword"; byte[] byteArray = Encoding.UTF8.GetBytes(postData); // Add the post data to the web request postStream.Write(byteArray, 0, byteArray.Length); postStream.Close(); // Start the web request webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest); } void GetResponseCallback(IAsyncResult asynchronousResult) { try { HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response; // End the get response operation response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); StreamReader streamReader = new StreamReader(streamResponse); var Response = streamReader.ReadToEnd(); streamResponse.Close(); streamReader.Close(); response.Close(); } catch (WebException e) { // Error treatment // ... } } private void button1_Click(object sender, RoutedEventArgs e) { DoWork(); } </code></pre> <p>his code adapted slightly from <a href="https://stackoverflow.com/questions/5952094/wp7-windows-phone-7-httpwebrequest-losing-post-data">this question</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload