I am trying to get message body from web service (located at http://www.ekkuli.net/conflict_call.php), which is returning 'Transfer-Encoding: chunked' tag and 409 Conflict response using the following code:
String webAddr = "http://www.ekkuli.net/conflict_call.php";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Method = "POST";
httpWebRequest.ServicePoint.Expect100Continue = false;
httpWebRequest.Accept = "application/json";
httpWebRequest.KeepAlive = true;
try {
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) {
String myJson = "{ \"method\" : \"just testing\" }";
streamWriter.Write(myJson);
streamWriter.Flush();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) {
var responseText = streamReader.ReadToEnd();
}
} catch (WebException ex) { // Catch 409 Conflict response
try {
// Try to get message body from 409 Response
var s = ex.Response.GetResponseStream();
var sr = new System.IO.StreamReader(s);
var content = sr.ReadToEnd(); // THIS THROWS AN EXCEPTION
} catch (Exception excep) {
// Exception! Error getting response stream (ReadAsync): ReceiveFailure Value cannot be null.
}
}
Is there any way to get response body from 409 Conflict -response, when server is returning 'Transfer-encoding: Chuncked' -header? If this header is disabled and Content-length is returned instead, everything works fine, but in this case I cannot modify the server code.
Same problem occurs, when trying with RestSharp -library (it returns status code 0 and message body 0).
I am using Mono (for Mac).