Hi, I recently got caught up on XCode and Xamarin updates. Now a Post from a real iPhone device gives me a 500 error while the same code in a Droid phone or an iPhone Simulator from Visual Studio works fine. Any ideas on how to fix this or investigate it further are appreciated.
`
private async Task<string> GetClientInfo(string ClientID)
{
string url = "";
Uri resourceAddress = new Uri("https://blahblah");
var values = new Dictionary<string, string>
{
{ "clientid", ClientID }
};
var content = new FormUrlEncodedContent(values);
HttpResponseMessage response = new HttpResponseMessage();
string clientID = "";
HttpClient httpClient = new HttpClient();
try
{
//////////////////////////////////////////////////////////////
// The following line is where it fails in an iPhone device
response = await httpClient.PostAsync(resourceAddress, content);
if (response.StatusCode == HttpStatusCode.OK)
{
string responseString = await response.Content.ReadAsStringAsync();
Dictionary<string, object> theData = JsonConvert.DeserializeObject<Dictionary<string, object>>(responseString, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
var results = theData["results"].ToString();
if (theData["client"] != null)
{
var client = theData["client"].ToString();
Dictionary<string, object> theData2 = JsonConvert.DeserializeObject<Dictionary<string, object>>(client, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
clientID = theData2["clientid"].ToString();
url = theData2["url"].ToString();
}
else
{
string msg = string.Format("ClientID {0} was not found.", ClientID);
Debug.WriteLine(msg);
WarningMsg = msg;
return url;
}
}
else
{ // Post failed
string msg = "LogInView GetClientInfo: Failed accessing web server (Post) for clientid " + ClientID + " Msg: " + response;
Util.DisplayErrors(msg, WarningMsg);
WarningMsg = msg;
}
}
catch (Exception ex)
{
string msg = "\n *** LogInView GetClientInfo: Exception when accessing web server (Post) for clientid " + ClientID + " Msg: " + ex.Message;
Util.DisplayErrors(msg, WarningMsg);
WarningMsg = msg;
return "";
}
return url;
}
`
Here are the results for different devices and simulators taken at the line where it fails for an iPhone device:
iOS iPhone and/or iPad:
{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.NSUrlSessionHandler+NSUrlSessionDataTaskStreamContent, Headers:
{
X-Powered-By: ASP.NET
Server: Microsoft-IIS/8.0
Date: Tue, 14 Mar 2017 16:50:22 GMT
X-Powered-By: ASP.NET
Content-Type: text/html
Content-Length: 75
}}
iPhone Simulator (iPhone 4s iOS 9.3) or (iPhone7 – iOS 10.2) run via Visual Studio:
{StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Server: Microsoft-IIS/8.0
X-Powered-By: PHP/5.6.30, ASP.NET
Date: Tue, 14 Mar 2017 17:54:38 GMT
Content-Length: 129
Content-Type: application/json
}}
Android phone:
{StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Server: Microsoft-IIS/8.0
X-Powered-By: PHP/5.6.30, ASP.NET
Date: Tue, 14 Mar 2017 17:51:03 GMT
Content-Length: 129
Content-Type: application/json
}}