Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For some reason, I am not able to read the response from the server instead it give the error " The remote server returned an error: (502) Bad Gateway" however if I check the server logs - it sends the response, can anyone let me know if I am missing something for not able to receive the response

C#
try
{
  DOMFlightAvailabilityPortTypeClient obj = new DOMFlightAvailabilityPortTypeClient();
  string req = "<Request>"
  + "<Origin>BOM</Origin>"
  + "<Destination>DEL</Destination>"
  + "<DepartDate>2014-11-20</DepartDate>"
  + "<ReturnDate>2014-12-21</ReturnDate>"
  + "<AdultPax>1</AdultPax>"
  + "<ChildPax>0</ChildPax>"
  + "<InfantPax>0</InfantPax>"
  + "<Currency>INR</Currency>"
  + "<Clientid>12345</Clientid>"
  + "<Clientpassword>12345</Clientpassword>"
  + "<Clienttype>12345</Clienttype>"
  + "<Preferredclass>E</Preferredclass>"
  + "<mode>ONE</mode>"
  + "<PreferredAirline>AI,G8,IC,6E,9W,S2,IT,9H,I7,SG</PreferredAirline>"
  + "</Request>";

  string str = obj.getAvailability(req);
  XmlDocument doc = new XmlDocument();
  doc.LoadXml(str);
  DataSet ds = new DataSet();
  ds.ReadXml(new XmlTextReader(new StringReader(str)));
  GridView1.DataSource = ds.Tables[0];
  GridView1.DataBind();
}
catch (WebException ex)
{
  if (ex.Status == WebExceptionStatus.ProtocolError)
  {
     WebResponse resp = ex.Response;
     using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
     {
         Response.Write(sr.ReadToEnd());
     }
  }
}
Posted
Updated 29-Jun-23 4:58am
v2

Error 502 "Bad Gateway" is an internal server error and generally has nothing to do with your code, but with internal communications between the web server and the database system or similar.

Talk to your web server hosting people: they may be able to sort it.
 
Share this answer
 
Add below lines in request:

req.Proxy = WebRequest.DefaultWebProxy;
req.ContentType = "application/x-www-form-urlencoded";
/// In order to solve the problem with the proxy not recognising the user
/// agent, a default value is provided here.
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)";
 
Share this answer
 
Comments
Richard Deeming 5-Jul-23 5:08am    
An unformatted, unexplained code-dump which won't even compile is NOT a "solution" to this nine-year-old question.

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