I encountered this error System.Net.WebException: The remote server returned an error: (400) Bad Request.
on the line below
response = request.GetResponse();
Any idea to solve it
public void call()
{
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
(s, cert, chain, sslPolicyErrors) => true;
string requestString = HttpUtility.UrlPathEncode("idata=" +"C:/JobPostingTest.xml");
string HUD_URL = "https://208.71.198.74:8443/bgwBroker"; .
string uName = "xtestxftp";
string pWord = "ftp12345";
HttpWebRequest request = null;
WebResponse response = null;
request = (HttpWebRequest)WebRequest.Create(HUD_URL);
request.Credentials = new NetworkCredential(uName, pWord);
request.Method = "POST"; // Set the Method property of the request to POST.
request.ContentType = "application/x-www-form-urlencoded; charset=ISO-8859-1";
StreamWriter sw = new StreamWriter(request.GetRequestStream()); // Wrap the request stream with a text-based writer
sw.WriteLine(requestString); // Write the xml as text into the stream
sw.Close();
response = request.GetResponse(); // Send the data to the webserver // Get the response.
if (request != null) request.GetRequestStream().Close(); //Close the request object
string responseFromServer = string.Empty;
if (response != null)
{
StreamReader incomingStreamReader = new StreamReader(response.GetResponseStream());
responseFromServer = incomingStreamReader.ReadToEnd(); // Put the response in a string
incomingStreamReader.Close();
response.GetResponseStream().Close();
//lbl_ResponseInfo.Text = ((HttpWebResponse)response).StatusDescription.ToString(); // Display the status.
}
XmlDocument xm = new XmlDocument();
xm.LoadXml(string.Format("<root>{0}", responseFromServer));
xm.Save(@"C:\Users\DELL\Documents\Visual Studio 2012\Projects\testXML\testXML\file.xml");
}