开发者

How can I make a request with both GET and POST parameters?

开发者 https://www.devze.com 2023-01-23 08:29 出处:网络
Here\'s an excerpt from Live HTTP headers, I\'ve replaced several values for anonymity. POST blah/admin.php?module_id=1&action=update&id=129&pageNum=17&&eid=362 HTTP/1.1

Here's an excerpt from Live HTTP headers, I've replaced several values for anonymity.

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,u开发者_StackOverflowtf-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

This request has both GET and POST values. The script on the other end of this is PHP and expects certain values to be in the GET and others to be in the POST.

I know how to issue a GET

curl -G -d "key=val" "http://yadayadayada"

And I understand how to do a POST

curl -d "key=val" "http://yadayadayada"
curl -F "key=val" "http://yadayadayada"

But how do I mix the two in a single request? Every attempt I've made so far has ended in an error.


GET variables can be included in the URL. You just include the GET variables in the query string. For example, if you wanted to send a GET request with "username=fred" to www.example.com/index.php, you would send a simple GET request to "http://www.example.com/index.php?username=fred". So to answer your question, just use the POST method, but have the URL contain your GET data.


To clarify, GET and POST are HTTP request methods, not value types.

  • GET variables are called query string parameters. They are part of the URL, and can be included in any request.
  • POST variables are the contents of a urlencoded message body. These might also be sent with a PUT request.

Therefore, if you want to send both types of values, send the POST data as normal while explicitly writing your query string.

curl -d "key=val" "http://example.com?query_var=1"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号