Santhosh

Santhosh

  • NA
  • 300
  • 140k

System.Net.WebException:The remote server returned 400 error

Nov 29 2016 1:28 AM
Hi,
 

When I post the data to my local server it will display this error.I'm a beginner to Andriod.driod.

I am developing sample Xamarin andriod application in my Visual studio 

"System.Net.WebException: The remote server returned an error: (400) Bad Request."
Timed out waiting for response from server

 
try
{
string url = "http://192.168.1.88:8044/api/sampleLocation/";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentLength =0;
//using GET - request.Headers.Add ("Authorization","Authorizaation value");
request.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse myResp = (HttpWebResponse)request.GetResponse();
string responseText;
using (var response = request.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
responseText = reader.ReadToEnd();
Console.WriteLine(responseText);
var forth = new Intent(this, typeof(SecondActivity));
forth.PutExtra("responseText2", locationText.Text);
StartActivity(forth);
}
}
}
catch (WebException exception)
{
string responseText;
using (var reader = new StreamReader(exception.Response.GetResponseStream()))
{
responseText = reader.ReadToEnd();
Console.WriteLine(responseText);
}
}
}

Answers (2)