System.Net.WebException: The remote server returned an error: (400) Bad Request.in var httpResponse

Soni
Soni edited July 2019 in .Net API client
protected void Page_Load(object sender, EventArgs e)
{
string url = string.Format("http://");
WebRequest requestObjPost = WebRequest.Create(url);
requestObjPost.Method = "POST";
requestObjPost.ContentType = "application/json";
requestObjPost.Credentials = new NetworkCredential("abc", "1234");



string postdata = "{\"name\":\"abcapi08\",\"ut_id\":1,\"org_id\":930,\"email_id\":\"[email protected]\",\"username\":\"abcapi08\",\"Password\":\"1234\"}";

using (var streamWriter = new StreamWriter(requestObjPost.GetRequestStream()))
{
streamWriter.Write(postdata);
streamWriter.Flush();
streamWriter.Close();


var httpResponse = (HttpWebResponse)requestObjPost.GetResponse();

using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
}
}
Sign In or Register to comment.