Click here to Skip to main content
15,745,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 = ""; .
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

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
//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");


1 solution

It seems that you and amiach working on the same project (homework?) so why not to join forces...
See my solution for his question (it's in the comments)...
The remote server returned an error: (403) Forbidden[^]
Share this answer
chouchay 31-Mar-14 7:13am    
I try to solve it but in vain , I already read the doc that you post but it was not solved , can you check the code with me please ?
Kornfeld Eliyahu Peter 31-Mar-14 7:15am    
You missed my last comment there... publishing a soap service via wsdl.
All that you need to do is adding a web reference to that address to your project, create a new object from the proxy type, than call the desired function at your will.
What are you doing now is just not right for that kind of service...
chouchay 31-Mar-14 9:11am    
I tried this solution and the proxy class dosn't provide all the necassery services .
I added a web references from the wsdl file and MonsterBusinessGatewayService contains methdos , this my code below but I encountred a problem to receive postingId from jobResponse to consult if the jobOffer is posted or not :
public string call()
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
(s, cert, chain, sslPolicyErrors) => true;

//service class gateway = new MonsterBusinessGatewayService();;

// consulter le nombre de view de job et et le nombre de postulation

job.RecruiterReference = rec;
var r = rec.UserName = "xtestxftp";
job.RecruiterReference.UserName = r;
job.jobRefCode = "testJob";
job.JobInformation = info;
info.JobTitle = "software engineer";
info.JobBody = BodyType;
var v = BodyType.Value = "intersting job ppppppppppppppppppphhhhhhhhhhhhhfffffffff ";
info.JobBody.Value = v;
JobPostingType[] jobPostings =new JobPostingType[10];
job.JobPostings = jobPostings;
jobPostings[1] = Postingtype;
Postingtype.Location = location;
location.CountryCode = "TN";
Postingtype.BoardName = BoardGroupId;
BoardGroupId.monsterId = "178";
Postingtype.JobCategory = CategoryType;
CategoryType.monsterId= "1";
JobOccupationType[] occupationType = new JobOccupationType[10];
Postingtype.JobOccupations = occupationType;
occupationType[1] = OccupationType;
OccupationType.monsterId = 11893;
job.jobAction = JobJobAction.delete;
Postingtype.jobPostingAction = JobPostingTypeJobPostingAction.delete;

// posting Stats
PostingStats postS = new PostingStats();
Postingtype.PostingStats = postS;
var nb = postS.Views;
var nbApp = postS.SeekerApps;

//Business Gataway paramaters
Kornfeld Eliyahu Peter 31-Mar-14 9:12am    
"but I encountred a problem" - what problem?
chouchay 31-Mar-14 9:13am    
the JobResponse is null and the jobOffer is not posted on Monster

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900