标签云

微信群

扫码加入我们

WeChat QR Code

In an HTTP GET request, parameters are sent as a query string:http://example.com/page?parameter=value&also=anotherIn an HTTP POST request, the parameters are not sent along with the URI.Where are the values? In the request header? In the request body? What does it look like?


I had forgot about file uploads being different (+1/accepted). Your answer is sufficient, while it would be extra nice if it had more info on multipart/form-data. For those interested though, here's a question about it.

2019年07月24日35分54秒

NOTE:the body is separated from the header by just one blank line.

2019年07月24日35分54秒

You explained what we place in the HTTPBody, but what do we place/write in the HTTPHeader? What purpose does it serve?

2019年07月23日35分54秒

Honey: The HTTP header for a post looks like one for a get, but with the verb POST instead of GET, and a content type value (and an optional content length value) as the request has content (body). Every type of request has a header, some types also have a body.

2019年07月24日35分54秒

KennethWorden No, non of the methods will properly send JSON. you can however upload a json file in a form encoded with multipart/form-data or if you're in charge of request construction, change content-type to application/json and paste json text in http body directly

2019年07月24日35分54秒

Only if the content type is application/x-www-form-urlencoded, which is not always the case.

2019年07月24日35分54秒

Camilo Martin .... [+1] for great question & Joe Alfano .... [+1] for great answer ....... i got a clear idea now about the POST request.... but if a image comes along with key,value pair of data information ..... How does the structure of POST looks like ?

2019年07月23日35分54秒

Joe, Now why would you have a From header there?

2019年07月23日35分54秒

Joe, I love the random inclusion of the From header. IMO it's up there with the 418 HTTP status code.

2019年07月23日35分54秒

I may have gone on a slight tangent indeed. I added a "tl;dr" to the top of the answer which should make it clearer.

2019年07月24日35分54秒

I also just now edited it to reference RFC7231 instead of RFC2616 (which has been obsolete for a while). The main difference for this answer apart from the updated links, is in the "PUT" section.

2019年07月23日35分54秒

I thought PUT was handled differently than POST since it's supposed to be idempotent? stackoverflow.com/questions/611906/…

2019年07月23日35分54秒

rogerdpack You are not wrong. If you read the second paragraph in the PUT section, you will see that it is idempotent. POST in contrast can - by definition - not be. POST will always create a new resource. PUT will, if an identical resource exist replace it. So if you call POST 10 times, you will create 10 resources. If you call PUT 10 times, it will (maybe) create only one. Does that answer your question?

2019年07月24日35分54秒

Ty for remembering the Host field.

2019年07月24日35分54秒

Clarification: is Content-Length supposed to be 29 here? That's the actual length of the string username=zurfyx&pass=password.

2019年07月24日35分54秒

Hippo was a newline character meant to be there?

2019年07月24日35分54秒

vikingsteve I see what you mean. So I guess the Content always has a newline at the end of it, then.

2019年07月23日35分54秒

The header is separated from body with extra newline

2019年07月23日35分54秒

You explained what we place in the HTTPBody, but what do we place/write in the HTTPHeader?

2019年07月23日35分54秒

You mentioned tha the key can be duplicate, then what is the outcome of such a duplicate? Will the last one will automatically overwrite the previous value(s)? Thanks.

2019年07月23日35分54秒

The difference between /user/john and /?user=john is merely a semantic one (HTTP doesn't really give special treatment to query strings), so I take this as reasonably expected. But what do you mean by "wrapped by space on the left"? There aren't spaces before the HTTP method. You mean the blank line for post body?

2019年07月23日35分54秒

There is a space (ASCII #32) between ...Ym04 and HTTP/1.1 in the above code. So a QueryString simply resides between the verb and the protocol version.

2019年07月24日35分54秒

Your note makes it sound like it's something unexpected and version-specific. Quite frankly it seems obvious there's a space there. And the line feed also applies to the other lines, like all things unix.

2019年07月24日35分54秒

I just emphasized what I couldn't mark out in code. It may seem obvious but sometimes it is not.

2019年07月24日35分54秒

It's true that we could pass the query parameters as part of the URL by separating the URI and the parameters with a ? like we do with GET requests.

2019年07月23日35分54秒

"Same format" is a bit ambiguous. Do they begin with an ? for example?

2019年07月24日35分54秒

PeterWooster Yes, but doesn't provide an example. In that regard, is like an answer that says "look, there's an answer for your question in the application's blog (link)".

2019年07月24日35分54秒

PeterWooster It isn't needed, but it's very good when you forget something, google it, go to the first link which is SO, and there's a clear, concise example that tells you what you need instead of sending you to chew on the excessively-detailed specs that, even if comprehensive, may be unfit for refreshers. Think about it: most of the QAs on this site could boil down to "go read the spec/manual/API/etc (link)". Would it be useful? Not more than Google.

2019年07月24日35分54秒

Only if the content type is application/x-www-form-urlencoded, which is not always the case.

2019年07月24日35分54秒

The format of GET query string is different from that of application/x-www-form-urlencoded. For example, whitespace is encoded differently (%20 vs +). The answer is misleading in this regard.

2019年07月23日35分54秒

The assumptions about security are only true in the context of a HTTPS connection, not HTTP. HTTPS encrypts both the URL (including query params) and the Request Body, when HTTP encrypts/protects neither. The issue described comes from the fact that many browsers store the URIs (including URLs) in their history databases (usually not encrypted). So, use only the Request Body+HTTPS for anything sensitive.

2019年07月23日35分54秒

PetruZaharia I agree with your explanation. You can also suggest this as edit and I will be happy to accept! :)

2019年07月24日35分54秒