【问题标题】:http post request curlhttp post 请求 curl
【发布时间】:2015-04-02 19:44:49
【问题描述】:

我有这个网站,在那里我提出了一个 http 发布请求 http://requestmaker.com/

我的问题是如何使用 curl 或其他类似的命令行应用程序发出此请求? windows 或 linux 无所谓。

我的请求 URL 是这样的:

http://www.website.net/servers?server%5Bgame%5D=cstrike1&server%5Bdomain%5D=192.168.1.1&server%5Bport%5D=27000

请求标头:

Content-Type: application/json
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Refer: http://www.website.net/servers/new

【问题讨论】:

  • 你读过documentation了吗?
  • 是的,但不是全部,我不是这些东西的专家。

标签: http curl http-post httprequest


【解决方案1】:

那就是:

curl -H "Content-Type: application/json" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" -H "Accept-Encoding: gzip, deflate" -H "Refer: http://www.website.net/servers/new" "http://www.website.net/servers?server%5Bgame%5D=cstrike1&server%5Bdomain%5D=192.168.1.1&server%5Bport%5D=27000"

但我认为您的意思是设置 Referer 标头而不是 Refer 并且您可能应该 POST JSON 数据,因为 Content-Typeapplication/json

【讨论】:

  • 不要忘记-d 用于发布的实际 JSON 数据。您还可以将-A 用作用户代理,将-e 用作引荐来源网址,而不是手动使用-H。您也不应该手动发送Accept-Encoding,除非您准备自己解码压缩的响应数据,否则请改用--compressed,让curl处理它。
  • 是的,我的意思是Referer,另一个错误是 Content-Type 它应该是 Content-Type: application/x-www-form-urlencoded 但它不起作用。
  • 那么您可能应该使用-d "server[game]=cstrike1&server[domain]=192.168.1.1&server[port]=27000" 来发布这些参数,而不是在 GET 中将它们作为查询参数传递
猜你喜欢
  • 2015-05-13
  • 1970-01-01
  • 2013-08-03
  • 2017-09-06
  • 2014-10-11
  • 1970-01-01
  • 2014-07-01
  • 2017-11-25
  • 1970-01-01
相关资源
最近更新 更多