Note that there are some explanatory texts on larger screens.

plurals
  1. POWP7 HttpWebRequest POST, server returns "{ result: 'ok' }\" in emulator, but "error: NotFound" on device
    primarykey
    data
    text
    <p>I'm trying to do a very basic http POST to a web service from my Windows Phone 7 app. I know the web service works fine because I'm using it for three other mobile platforms.</p> <p>I've modified the C# example from <a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.begingetrequeststream.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.begingetrequeststream.aspx</a></p> <pre><code> string boundary = DateTime.Now.Ticks.ToString(); private void POST_TEST(object sender, RoutedEventArgs e) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.JSON_URL_PREFIX + Settings.Settings.DeviceID + "/inquiry/new/"); request.ContentType = "multipart/form-data; boundary=" + boundary; request.Method = "POST"; request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request); } public void GetRequestStreamCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; Stream postStream = request.EndGetRequestStream(asynchronousResult); StringBuilder postData = new StringBuilder(); postData.Append("--" + boundary + "\r\n"); postData.Append("Content-Disposition: form-data; name=\"body\"\r\n\r\n"); postData.Append("test 123"); postData.Append("\r\n--" + boundary + "\r\n"); byte[] byteArray = Encoding.UTF8.GetBytes(postData.ToString()); postStream.Write(byteArray, 0, postData.Length); postStream.Close(); request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request); } private static void GetResponseCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; // End the operation HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); StreamReader streamRead = new StreamReader(streamResponse); string responseString = streamRead.ReadToEnd(); // Close the stream object streamResponse.Close(); streamRead.Close(); // Release the HttpWebResponse response.Close(); } </code></pre> <p>I'm receiving "{ result: 'ok' }" from the server when I run this in the emulator, but "error: NotFound" when I run it on my Samsung Focus. I'm assuming this has to do with the way a string is converted to a byte[] on the phone versus a desktop computer.</p> <p>Any ideas on a fix? Maybe this is a known error that I never ran across searching the web for an answer?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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