I am using a .net webservice to communicate via JSON with an external API (Urban Airship). There is something incorrect in my outbound JSON, and supposedly, along with the 400 Bad Request error I am seeing, they are returning a JSON object to me that has error logging that will help me identify the problem.
Only thing is, I can't figure out how to accept and read the JSON error message... all I get is the 400 Bad Request. Is there a way I can modify my code to see this returned object?
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);
req.ContentType = contentType;
req.Method = method;
req.ContentLength = jsonDataBytes.Length;
CredentialCache credentialCache = new CredentialCache();
string username = "x";
string password = y
credentialCache.Add(uri, "Basic", new NetworkCredential(username, password));
req.Credentials = credentialCache;
req.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(username + ":" + password)));
req.Accept = "application/vnd.urbanairship+json; version=3;";
dynamic stream = req.GetRequestStream();
stream.Write(jsonDataBytes, 0, jsonDataBytes.Length);
stream.Close();
dynamic response = req.GetResponse().GetResponseStream();
StreamReader reader = new StreamReader(response);
dynamic res = reader.ReadToEnd();
reader.Close();
response.Close();