Hi All,

I want to develop asp.net web-site by using API provided by cleartrip. I used that API but every time I received the response as bad request. Please help me to soulve the issue.

Here is my Code:-

HttpWebRequest req = (HttpWebRequest)WebRequest.Create();
 
req.Method = "Get";
req.Headers.Add("X-CT-API-KEY", "MYAPIKEY");
 
HttpWebResponse oResponse;
oResponse =(HttpWebResponse) req.GetResponse();

Plese check the attached file for erroe details. (BAD REQUEST].

Thanks

Dani AI

Generated

Common causes for a 400 when a .NET HttpWebRequest hits a travel/booking API are an invalid endpoint or query string, an unexpected request format (missing or wrong headers), using the wrong environment (staging key vs production endpoint), or the server rejecting the TLS/protocol used. In this thread posted a minimal request and flagged the URL; ’s suggestion to exercise the call from a REST client is exactly the right next step — the server’s error body usually explains what it didn’t like.

Recommended, ordered checks:

  • Verify the exact endpoint and whether the API key is for that environment (staging vs production).
  • Reproduce the same request in Postman / curl / a REST client to see the raw response body and headers (that often shows a descriptive error).
  • Ensure query parameters are properly URL-encoded and match the API’s expected names and formats (date formats are a common gotcha).
  • Send the HTTP method token exactly as the API expects (use "GET"), and include the Accept/Content-Type the API expects (XML or JSON).
  • Capture the server’s error body from .NET by catching WebException — that body usually contains the actionable error string to pass to support.

A short C# pattern to capture the real server response (replace the URL and header name with the values required by the API):

try
{
    var req = (HttpWebRequest)WebRequest.Create(new Uri("https://api.example.com/air/1.0/search?from=BOM&to=DEL&depart-date=2010-12-20"));
    req.Method = "GET";
    req.Accept = "application/xml";
    req.Headers["X-API-KEY"] = "REPLACE_WITH_KEY";

    using (var resp = (HttpWebResponse)req.GetResponse())
    using (var r = new StreamReader(resp.GetResponseStream()))
    {
        Console.WriteLine((int)resp.StatusCode + " " + resp.StatusDescription);
        Console.WriteLine(r.ReadToEnd());
    }
}
catch (WebException ex) when (ex.Response is HttpWebResponse er)
{
    using (var sr = new StreamReader(er.GetResponseStream()))
    {
        Console.WriteLine((int)er.StatusCode + " " + er.StatusDescription);
        Console.WriteLine(sr.ReadToEnd()); // diagnostic payload from the API
    }
}

Note: APIs are language-agnostic, so the same HTTP call can be made from PHP (cURL or a HTTP client). Since this thread is old, API headers/requirements may have changed — a captured raw request/response is the most useful artifact to include when contacting Cleartrip support.

Recommended Answers

All 3 Replies

Presumably because its an invalid URL you're using?

Error 400: Requested URL invalid or incomplete

I have tried to use the website using the recommended example and it does not work - suspect the site has changed its policy for access

Try to get actual error message and contact Clerartrip Support

cleartrip apis will be avaliable in php ?

plz repy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.