Reputation: 4730
I'm trying to send a HTTP POST request to a Google server and get the response. I'm trying to send the exact same request that my browser would send. When I search, I checked the request and response from Chrome's developer tools. According to that, this is my request.
Request URL:http://www.google.com/hotelfinder/rpc
Request Method:POST
Status Code:200 OK
request headers:
POST /hotelfinder/rpc HTTP/1.1
Host: www.google.com
Connection: keep-alive
Content-Length: 116
Origin: http://www.google.com
X-GWT-Module-Base: http://www.google.com/hotelfinder/static/
X-GWT-Permutation: A237247005BD7F571F547C07F4E1BA8D
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1
Content-Type: application/json; charset=UTF-8
Accept: */*
Referer: http://www.google.com/hotelfinder/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: rememberme=true; --my cookie--
payload:
[,[[,"hs","[,[,\"Las Vegas, NV\",\"2011-10-02\",1]\n]\n"]
]
,[,[[,"b_ca","101"]
,[,"b_qu","0"]
,[,"b_qc","1"]
]
]
]
I used the Apache HTTP client to send the request but am only getting a page with that Google top bar. Please help me to do this.
Upvotes: 1
Views: 2347
Reputation: 1108722
Open the page in a normal webbrowser, rightclick and View Source. That's exactly what HttpClient also retrieves. Do you see that bunch of JavaScript? Disable JavaScript in your browser, refresh the page. Do you now see that you get the same result (only the Google top bar)?
In other words, JavaScript is required. You've to parse, interpret and execute JavaScript yourself. HttpClient doesn't do that, it just gives you the same as whatever your webbrowser retrieves as you can see in View Source. Your HttpClient code is working perfectly fine. The only difference is that your webbrowser is able to parse, interpret and execute JavaScript.
That said, I wonder if you realize that you're actually violating their terms of service this way. I suggest to look for a public hotel finder webservice API. This question has been asked before: Travel/Hotel API's?
Upvotes: 2