My Windows Phone app Get empty response (404 Not Found) Scond time, work's great first time;And always work fine if without SSL
Please try to use this solution.
public async Task<string> SendJSONData3(string urlToCall, string JSONData) { string UserName = "XXXXXXXXX"; string Password = "XXXXXXXXX"; var httpWebRequest = (HttpWebRequest)WebRequest.Create(urlToCall); httpWebRequest.Credentials = new NetworkCredential(UserName, Password); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(await httpWebRequest.GetRequestStreamAsync())) { string json = JSONData; streamWriter.Write(json); streamWriter.Flush(); } var httpResponse = (HttpWebResponse)await httpWebRequest.GetResponseAsync(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); return result; } }
A couple of ideas:
- Do not use the
.Result
property. Just useawait
instead to avoid deadlocks. - Remove the additional space in front of the media type parameter
" application/json"
- Enable logging on the webserver and see if the second request arrives on the server.
- Get a network trace, for example with Wireshark or Fiddler.
- Try puting
WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);
in your initialization code, as proposed in this answer.