How to send raw data to an HTTP GET request?

In the example at http://alx3apps.appspot.com/jsonrpc_example/ , when I click the submit button, I notice (using Firebug) that my browser is sending the source code:

{"params":["Hello ","Python!"],"method":"concat","id":1} 

He did not publish the parameter (for example, json=[encoded string from above] ), but simply published an unprocessed string with the value indicated above.

Is there a common way to replicate this using a GET request, or do I just need urlencode the same line and include it as http://www.example.com/?json=%7b%22params%22%3a%5b%22Hello+%22%2c%22Python!%22%5d%2c%22method%22%3a%22concat%22%2c%22id%22%3a1%7d ? I understand that some older browsers cannot handle URIs of more than 250 characters, but I'm fine with that.

+4
source share
2 answers

A GET request usually does not pass the data in any other way than the headers, so you must pass the string encoded in the URL if you want to use GET.

 POST http://alx3apps.appspot.com/jsonrpc_example/json_service/ HTTP/1.1 Host: alx3apps.appspot.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-gb,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 Content-Type: application/json-rpc; charset=UTF-8 X-Requested-With: XMLHttpRequest Referer: http://alx3apps.appspot.com/jsonrpc_example/ Content-Length: 55 Pragma: no-cache Cache-Control: no-cache {"params":["Howdy","Python!"],"method":"concat","id":1} 

In the regular post form, the Content-Type: application/x-www-form-urlencoded header allows the server to know the format in key = val format, while the page associated with you sends Content-Type: application/json-rpc; charset=UTF-8 Content-Type: application/json-rpc; charset=UTF-8 . After the headers (which end with an empty line), the data follows in the specified format.

+3
source

You are correct that only POST transfers data separately from the URI. So urlencoding this in querystring is the only way to go if you should use GET. (Well, I suppose you could try setting custom request headers or using cookies, but the only “generally accepted” way is to use the request.)

+1
source

Source: https://habr.com/ru/post/1332383/


All Articles