What would a body in an HTTP GET look like? [duplicate] - http

This question already has answers here:
HTTP GET with request body
(23 answers)
Closed 8 years ago.
I realize this is not recommended, but I'm wondering what the URL would look like, for example:
http://myserver.com/rest/info?param1=foo&param2=bar
how would you append a body to that URL, I don't think &body would work.
Reason I'm looking at this is I'm looking for a way around a rather limited preset access to CURL from within my chosen language, so I'm wondering if I can use GET somehow instead of POST.
EDIT: Several people marked this as a duplicate of another question, but the essence of my question was "What would the body look like" where the other question is and I quote here from the other post:
My questions:
Is this a good idea altogether? Will HTTP clients have issues with
using request bodies within a GET request?
Therefore I don't believe this is a duplicate at all, I believe those who marked it as such perhaps didn't really read either question much beyond the title.

The URL wouldn't change by adding a body to the HTTP request. In addition to the normal HTTP headers your request would also include a body (separated from the header by a blank line).
I would strongly recommend that you DON'T do this with GET requests though - it is not well treated with HTTP servers and is somewhat wrong if you want to follow and respect the HTTP specification.
A simple request would look something like this:
GET /whatever HTTP/1.1
Host: foobar.com
User-Agent: Selfmade telnet
Connection: close
hello world

Related

How to add Parameters, Data, and Headers to a POST request in Golang? [duplicate]

This question already has an answer here:
How to translate this curl call into Go?
(1 answer)
Closed 1 year ago.
Is there any way to add headers and data to an HTTP request in Golang, as well as URL parameters? I have tried to add data to a POST request, but it seems Golang just isn't meant for sending any kind of complex request. After much research online I'm not sure if there's a way, but if anyone knows how, please tell me!
Yes, you can. See How to set headers in http get request?, it answers your question. Also, you can find more information about the default http package in https://pkg.go.dev/net/http.

Documentation for Rebol2's read/custom?

I've been trying to update Ross-Gill's Twitter API for REBOL2 to support uploading media. From looking at its source, the REBOL cookbook, the codeconscious site, and other questions here, my understanding is that read/custom is the preferred way to POST data to websites.
However, I haven't been able to find any real documentation on read/custom. For example: Does it support sending multipart/form-data? (I've managed to work around this by manually composing each part, but it doesn't seem to work for all image files on Twitter's end and is a bit of a hack). Does read/custom only return text on an HTTP/1.0 200 OK response? (It appears so, which is problematic when I receive HTTP/1.0 202 Accepted and need to read the resulting data). Is there a reason that read/custom/binary doesn't appear to send binary data correctly without converting the data using to-string?
TL;DR: Is there good documentation on REBOL2's read/custom somewhere? Alternatively, is read/custom only meant for basic POSTs and I should be using ports and handling the HTTP responses manually?
You guessed right, read/custom is meant for simple HTTP posts, handling web forms data only (that is why it will fail on binary data). No official documentation for it. But that is not an issue as you can access the source code of the HTTP implementation:
probe system/schemes/HTTP
There you can see that /custom refinement supports two keywords, post and header (for setting custom HTTP headers). It also appears that even if you use both keywords, Content-Type will be forced to application/x-www-form-urlencoded no matter what (which is probably the reason why your binary data gets rejected by the server, as the provided mime type is wrong).
In order to work around that, you can save the HTTP object, modify its implementation to fit your needs and reload it.
Saving:
save %http-scheme.r system/schemes/HTTP
Reloading:
system/schemes/HTTP: do load %http-scheme.r
If you just disable the hard-coded Content-Type setting in the HTTP code, and then provide your own one using header keyword, it should work fine, even with binary data:
read/custom <url> [header [Content-Type: <...>] post <data>]
Hope this helps.

What charset encoding is used for HTTP GET requests URL? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What's the correct encoding of HTTP get request strings?
One of my clients sent me they require HTTP requests to be encoded in ISO-8859-2,
so I wonder about what charset is used for HTTP communication, and if this request is somehow technicaly right.
It depends. A "smart" server will always use percent-escaped UTF-8, but you can't rely on that.
Pure ASCII is all that's allowed in HTTP headers. But, as far as HTTP is concerned, anything goes in the request body of a POST. The headers and body are always separated by a blank line. A set of headers will normally identify the format of the content/body. Responses work the same way. However, HTML has some additional rules regarding what normally goes in a POST.
EDIT: Sorry, I missed the word 'GET' in your title. Might be nice to duplicate that in the body of your question.
At any rate, I believe I am correct in saying ONLY ASCII (ANSI X3.4-1986) is allowed in the headers of any HTTP request, GET or POST. So no, ISO-8859-2 requests are not strictly valid HTTP. That said, there's probably a way to escape the desired special characters in the query string if that's what you're really asking for here.
SOURCE: https://www.rfc-editor.org/rfc/rfc2616

What is the difference between GET and POST methods? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
When do you use POST and when do you use GET?
I know the basic difference between GET and POST methods. That is we can see the URL parameters in case of GET and can't see the URL parameters in case of POST. Of course we can pass huge amounts of data by POST which is not possible through GET.
Are there any other differences between these two methods ?
GET is for data retrieval only. You can refine what you are getting but it is a read only setup and yes, as you mentioned anything used for refinement are part of the URL.
POST is meant for sending data, but is generally a way to 'break' the simple workings of HTML because you are neither guaranteed of anything that is happening, it can just fetch data, send data or delete data.
There are also PUT and DELETE in the HTML standards, but its all about finding web servers that support these actions as well. As the names imply PUT sends data for either the creation or updating while DELETE is for removal of data.
Enjoy! :)
Other implementation differences in GET and POST:
they have different encoding schemes. multipart/form-data is for POST only
the result of POST may not result in an actual page.
url limit necessitates use of POST
If you are using HIDDEN inputs in form then submitting a GET request reveals those inputs

POSTing to a URI with GET query params?

I stumbled upon some code the other day that was making use of query params specified in the URI while at the same time being an HTTP POST.
I was just wondering, is the interpretation of these fields vendor specific? Do the RFCs say anything specific about it? And if a parameter exists in both, which one wins out?
To illustrate better, the query looked something like this:
POST /posts/?user=bob HTTP/1.1
user=bill&title=Test&content=Testing+Content
Thanks
This is perfect legal. Many frameworks have support for it for example the Servlet API even specifies the priority (order) of the arguments as they appear in getParameters(String) which will provide the query parameter first. For example this is also legal, not the parameter names are the same.
POST /path?param1=value HTTP/1.1
Host: localhost
param1=value&param2=value
This is also valid according to the HTTP/1.1 RFC, a look at RFC 2616.
It should not be vendor specific, and most comprehensive frameworks will support it.
There is no trumping. The GET and POST values are passed as separate collections.
I do this occasionally. Usually i'll put the actual update fields in the post data, with query data used to format the response

Resources