I need help with HttpWebRequest in C #. Below lines of codes work fine for local IIS, but when I boot to the remote server, it starts giving me "The remote server returned an error: (500) Internal Server Error." I tried many options with the GET and POST method, but could not figure out what the problem was. Please read the code below and let me know what is wrong with this.
try
{
string postData = "applicaitonid=abc&deviceid=xyz";
string uri = System.Configuration.ConfigurationManager.AppSettings.Get("baseUrl") + System.Configuration.ConfigurationManager.AppSettings.Get("ABApiPath") + "ConfirmAppBinding/?" + postData;
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.UserAgent = Request.UserAgent.ToString();
request.ContentType = @"application/json";
request.MediaType = "application/json";
request.Accept = "application/json";
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version11;
request.Timeout = 500000;
Stream reqstr = request.GetRequestStream();
reqstr.Close();
var httpResponse = request.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
JsonMessage.message = streamReader.ReadToEnd();
streamReader.Close();
}
}
catch (WebException e)
{
JsonMessage.message = e.Message;
return Json(JsonMessage, JsonRequestBehavior.AllowGet);
}
As I said, I used the default GET method, but this did not solve the problem.
source
share