如何使用GET和POST参数发出请求?

Fre*_*red 21 post curl get

这是Live HTTP标题的摘录,我已经替换了匿名的几个值.

POST blah/admin.php?module_id=1&action=update&id=129&pageNum=17&&eid=362 HTTP/1.1

Host: blah

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Firefox/3.6.12

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

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 115

Connection: keep-alive

Referer: blah

Cookie: blah

Content-Type: multipart/form-data; boundary=---------------------------21278813472729408841849703914

Content-Length: 5110

-----------------------------21278813472729408841849703914

Content-Disposition: form-data; name="MAX_FILE_SIZE"



300000000
Run Code Online (Sandbox Code Playgroud)

此请求具有GET和POST值.另一端的脚本是PHP,并期望某些值在GET中,而其他值则在POST中.

我知道如何发布GET

curl -G -d "key=val" "http://yadayadayada"
Run Code Online (Sandbox Code Playgroud)

我知道怎么做POST

curl -d "key=val" "http://yadayadayada"
curl -F "key=val" "http://yadayadayada"
Run Code Online (Sandbox Code Playgroud)

但是如何在一个请求中混合使用这两个?到目前为止,我所做的每一次尝试都以错误结束.

Sam*_*uel 30

GET变量可以包含在URL中.您只需在查询字符串中包含GET变量即可.例如,如果您想将带有"username = fred"的GET请求发送到www.example.com/index.php,您可以向"http://www.example.com/index.php"发送简单的GET请求?用户名=弗雷德".所以要回答你的问题,只需使用POST方法,但让URL包含你的GET数据.

  • @latvian您需要逃离空间以使网址完全安全.在你的情况下,它将是http://www.example.com/index.php?username=fred%20johnson.在这里阅读有关网址编码的信息:http://www.blooberry.com/indexdot/html/topics/urlencoding.htm (5认同)
  • 如果你的param有像username ='fred johnson'这样的空格怎么办? (2认同)

Bra*_*och 10

为了澄清,GET和POST是HTTP请求方法,而不是值类型.

  • GET变量称为查询字符串参数.它们是URL的一部分,可以包含在任何请求中.
  • POST变量是urlencoded消息体的内容.这些也可能与PUT请求一起发送.

因此,如果要发送两种类型的值,请在显式写入查询字符串时正常发送POST数据.

curl -d "key=val" "http://example.com?query_var=1"
Run Code Online (Sandbox Code Playgroud)