0

I want to make a post request using HttpClient or XMLHTTP similar to this.

POST http://www.indianrail.gov.in/cgi_bin/inet_trnnum_cgi.cgiHTTP/1.1
        Host: www.indianrail.gov.in
    Connection: keep-alive
    Content-Length: 39
    Cache-Control: max-age=0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Origin: http://www.indianrail.gov.in
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36
    Content-Type: application/x-www-form-urlencoded
    Referer: http://www.indianrail.gov.in/train_Schedule.html
    Accept-Encoding: gzip, deflate
    Accept-Language: en-US,en;q=0.8

    lccp_trnname=19329&getIt=Please+Wait...

Have seen the code sample of httpclient, but I didn't understand much from that.Typically facing the problem in setting the headers.Below is what I have tried.Also, want to know how to send the string( lccp_trnname=19329&getIt=Please+Wait...) to the server.

httpClient = new Windows.Web.Http.HttpClient();

            httpClient.defaultRequestHeaders.host(new Windows.Networking.HostName("www.indianrail.gov.in"));
            httpClient.defaultRequestHeaders.connection("keep-alive");
            httpClient.defaultRequestHeaders.accept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
            httpClient.defaultRequestHeaders.userAgent.parseAdd("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
           httpClient.defaultRequestHeaders.referer("http://www.indianrail.gov.in/train_Schedule.html");
            httpClient.defaultRequestHeaders.acceptEncoding("gzip, deflate");
            httpClient.defaultRequestHeaders.acceptLanguage("en-US,en;q=0.8");
Amit Porwal
  • 43
  • 1
  • 1
  • 7
  • 1
    What does "it doesn't work" mean? Doesn't compile, throws exceptions, doesn't make the request? If it's the latter it could be that you never call anything to actually send the request. Look at postAsync (which will also answer your "Also"). – blm Oct 26 '15 at 18:56
  • @blm : Actually I 'm getting exception in setting the headers. – Amit Porwal Oct 27 '15 at 13:26
  • 1
    Ok, that's not at all clear from your question, and if you're getting an exception, _include the exception_! The more pertinent information you can include, the better the chances someone will be able to answer your question. – blm Oct 27 '15 at 16:30

0 Answers0