1

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:

  • About to connect() to suggestqueries.google.com port 443 (#0)
  • Trying 74.125.200.138... connected
  • successfully set certificate verify locations:
  • CAfile: none CApath: /etc/ssl/certs
  • SSLv3, TLS handshake, Client hello (1):
  • SSLv3, TLS handshake, Server hello (2):
  • SSLv3, TLS handshake, CERT (11):
  • SSLv3, TLS handshake, Server key exchange (12):
  • SSLv3, TLS handshake, Server finished (14):
  • SSLv3, TLS handshake, Client key exchange (16):
  • SSLv3, TLS change cipher, Client hello (1):
  • SSLv3, TLS handshake, Finished (20):
  • SSLv3, TLS change cipher, Client hello (1):
  • SSLv3, TLS handshake, Finished (20):
  • SSL connection using ECDHE-ECDSA-AES128-SHA
  • Server certificate:
  • subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.google.com
  • start date: 2014-08-27 11:47:20 GMT
  • expire date: 2014-11-25 00:00:00 GMT
  • subjectAltName: suggestqueries.google.com matched
  • issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
  • SSL certificate verify ok.

  • GET /complete/search?hl=en HTTP/1.1

  • User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0
  • Host: suggestqueries.google.com
  • Accept: application/xml
  • Content-Type: application/xml

  • HTTP/1.1 200 OK

  • Content-Type: text/html; charset=UTF-8
  • Set-Cookie: PREF=ID=221163cf51f1fd63:FF=0:TM=1410889133:LM=1410889133:S=8a7TwxXZ4a-1bM3l; expires=Thu, 15-Sep-2016 17:38:53 GMT; path=/; domain=.google.com
  • Set-Cookie: NID=67=UiY78HgmkOLxvy0S4_EfmD7vRX0gInDI6FhWWuj2cP9w25NfV6DdzVq7XooHlo5QNH1NteyjxWqyDVm0Dp9OD8Y7ABx-GEOy-wYEHDEciDmIxFhCFxixOXO1RJIn5UL_; expires=Wed, 18-Mar-2015 17:38:53 GMT; path=/; domain=.google.com; HttpOnly
  • P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
  • Date: Tue, 16 Sep 2014 17:38:53 GMT
  • Server: gws
  • Content-Length: 0
  • X-XSS-Protection: 1; mode=block
  • X-Frame-Options: SAMEORIGIN
  • Expires: Tue, 16 Sep 2014 17:38:53 GMT
  • Cache-Control: private
  • Alternate-Protocol: 443:quic,p=0.002

  • Connection #0 to host suggestqueries.google.com left intact

  • Closing connection #0
  • SSLv3, TLS alert, Client hello (1):

  • 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

  • Done q=test
  • Done gl=US
4

2 回答 2

0

获取wireshark并检查包裹。它可能没用,因为我可以看到 curl 使用 SSL。但是,您可以检查您的浏览器是否也使用 SSL。如果没有,您将获得完整的软件包,您可以将其与 curl 输出进行比较并找出哪个字段导致错误(也检查来自谷歌的响应,它们可能不仅会因 400 响应而有所不同)。

于 2014-09-16T19:14:43.900 回答
0

您必须将网址放在引号中,请尝试:

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

&在大多数 shell 中都经过特殊处理。

正如您在发布的错误中看到的那样,网址在第一个&之前被剪切:

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
                                                                       ^
                                                                       |
于 2015-11-11T21:19:03.493 回答