本文介绍了我如何在HTTP GET请求中发送原始数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我点击时的示例中提交按钮,我注意到(通过使用Firebug)我的浏览器提交源:

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

发布一个参数(例如 json = [来自上面的编码字符串] ),而不是发布一个具有上述值的原始字符串。

是否有一种广为接受的方式通过GET请求来复制它,还是只需要urlencode相同的字符串并将其包含为 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 ?我了解到一些旧浏览器无法处理超过250个字符的URI,但我确定。

解决方案

A GET请求通常不会以除标头以外的其他任何方式传输数据,因此如果您希望使用GET,则应传递在URL中编码的字符串。

  POST http://alx3apps.appspot.com/jsonrpc_example/json_service/ HTTP / 1.1 
主机:alx3apps.appspot.com
用户代理:Mozilla / 5.0(Windows; U ; Windows NT 6.1; en-GB; rv:1.9.2.13)Gecko / 20101203 Firefox / 3.6.13
接受: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
连接: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 }

在标题 Content-Type:application / x -www-form-urlencoded 让服务器知道期望key = val格式的格式,而你链接的页面发送 Content-Type:application / json-rpc;字符集= UTF-8 。在标题(以空白行结尾)后,数据以指定的格式显示。


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

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

It's not posting a parameter (eg. json=[encoded string from above]), but rather just posting a raw string with the above value.

Is there an widely accepted way to replicated this via a GET request, or do I need to just urlencode the same string 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 a URI of more than 250 characters, but I'm OK with that.

解决方案

A GET request doesn't usually transmit data in any other way besides headers, so you should pass the string encoded in the URL if you wish 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 a normal form post the header Content-Type: application/x-www-form-urlencoded lets the server know to expect the format in key=val format whereas the page you linked sends Content-Type: application/json-rpc; charset=UTF-8. After the headers (which are terminated with the blank line) the data follows in the specified format.

这篇关于我如何在HTTP GET请求中发送原始数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 22:42