RKP
RKP

Reputation: 174

Google suggest query using curl

When I am doing request using different browser it is giving me proper xml response.

http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=test&gl=US

Now I am request above url using curl command but it is giving me 400 error:

curl http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=test&gl=US

Also I have passed user-agent but it is also giving me same error.

curl -A "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0"  http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=test&gl=US

Please guide If I missing somethings.

ERROR

400. That’s an error.

Your client has issued a malformed or illegal request. That’s all we know.

When I am trying below command:

curl -v -A "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0" -H "Accept: application/xml" -H "Content-Type: application/xml" https://suggestqueries.google.com/complete/search?hl=en&q=test&gl=US&format=rich

Then getting response:

Upvotes: 1

Views: 2925

Answers (2)

joewhite86
joewhite86

Reputation: 418

You have to put the url in quotes, try:

curl 'http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=test&gl=US'

the & is treated specially in most shells.

As you can see in the error you posted, the url is cut before the first &:

Done curl -v -A "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:27.0) 
Gecko/20100101 Firefox/27.0" -H "Accept: application/xml" -H "Content-Type: 
application/xml" https://suggestqueries.google.com/complete/search?hl=en
                                                                       ^
                                                                       |

Upvotes: 0

MKAROL
MKAROL

Reputation: 316

Get wireshark and check the packages. It could be useless because I can see that curl use SSL. However you can check if your browser use SSL too. If not you get the full package that you can compare to curl output and find out which field cause error(check responses from google too, they may vary not only by 400 response).

Upvotes: 0

Related Questions