使用JSON参数对GET进行卷曲.来自服务器的空回复 [英] Curl GET with JSON parametr. Empty reply from server

查看:109
本文介绍了使用JSON参数对GET进行卷曲.来自服务器的空回复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

curl命令有问题.我想使用JSON参数发送请求(GET),我应该从服务器那里得到一些答案,但不幸的是我什么也没得到. 在最好的情况下,我会从下面的答复表格服务器中获取

I have a problem with curl command. I want to send request (GET) with JSON parametr, and I should get some answer from server but unfortunately I nothing get. In the best case I get below answer form server

* Hostname was NOT found in DNS cache
*   Trying 192.168.1.101...
* Connected to 192.168.1.101 (192.168.1.101) port 80 (#0)
> GET /ckk.cgi HTTP/1.1
> User-Agent: curl/7.38.0
> Host: 192.168.1.101
> Accept: application/json
> Content-type: application/json
> Content-Length: 41
> 
* upload completely sent off: 41 out of 41 bytes
* Empty reply from server
* Connection #0 to host 192.168.1.101 left intact
curl: (52) Empty reply from server

我阅读了以下主题:

使用json参数卷曲GET请求 如何发布JSON从终端/命令行使用Curl来测试Spring REST?

所以我尝试了以下命令

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET 192.168.1.101/ckk.cgi?json={"asking1":{"001":"givnames1","_id":223}}

curl -H "Content-Type: application/json" -X GET -d '{"asking1":{"001":"givnames1","_id":223}}' http://192.168.1.101/ckk.cgi?

curl -X GET -H "application/json" -d '{"asking1":{"001":"givnames1","_id":223}}' http://192.168.1.101/ckk.cgi?

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X GET -d '{"asking1":{"001":"givnames1","_id":223}}' http://192.168.1.101/ckk.cgi?

curl -i GET -H "Accept: application/json" "http://192.168.1.101/ckk.cgi??json={"asking1":{"001":"givnames1","_id":223}}"

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET -d '{"asking1":{"001":"givnames1","_id":223}}}' 

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET -d "{"asking1":{"001":"givnames1","_id":223}}" http://192.168.1.101/ckk.cgi?

curl --data "{"asking1":{"001":"givnames1","_id":223}}}" http://192.168.1.101/ckk.cgi?

curl -v  http://192.168.1.101/ckk.cgi? --header "Content-Type: application/json" -d "{"asking1":{"001":"givnames1","_id":223}}"

所有命令均无效....

All command doesn't works....

浏览器中的Works命令只是:

192.168.1.101/ckk.cgi?json={"asking1":{"001":"givnames1","_id":223}}

以下是问题的答案

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET 192.168.1.101/ckk.cgi?json={"asking1":{"001":"givnames1","_id":223}}

HTTP/1.1 200 OK
Date: Sat, 24 Oct 2015 04:58:11 GMT
Server: Apache/2.4.12 (Unix) OpenSSL/1.0.2c
Content-Length: 0
Content-Type: text/html;charset=utf-8

HTTP/1.1 200 OK
Date: Sat, 24 Oct 2015 04:58:16 GMT
Server: Apache/2.4.12 (Unix) OpenSSL/1.0.2c
Content-Length: 0
Content-Type: text/html;charset=utf-8

 curl -vv -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET 192.168.1.101/ckk.cgi?json={"asking1":{"001":"givnames1","_id":223}}

* Hostname was NOT found in DNS cache
*   Trying 192.168.1.101...
* Connected to 192.168.1.101 (192.168.1.101) port 80 (#0)
> GET /skk.cgi?json=asking1:001:givname1 HTTP/1.1
> User-Agent: curl/7.38.0
> Host: 192.168.1.101
> Accept: application/json
> Content-Type: application/json
> 
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Sat, 24 Oct 2015 05:33:39 GMT
Date: Sat, 24 Oct 2015 05:33:39 GMT
* Server Apache/2.4.12 (Unix) OpenSSL/1.0.2c is not blacklisted
< Server: Apache/2.4.12 (Unix) OpenSSL/1.0.2c
Server: Apache/2.4.12 (Unix) OpenSSL/1.0.2c
< Content-Length: 0
Content-Length: 0
< Content-Type: text/html;charset=utf-8
Content-Type: text/html;charset=utf-8

< 
* Connection #0 to host 192.168.1.101 left intact
* Found bundle for host 192.168.1.101: 0x7f53c7dbb5a0
* Re-using existing connection! (#0) with host 192.168.1.101
* Connected to 192.168.1.101 (192.168.1.101) port 80 (#0)
> GET /ckk.cgi?json=asking:_id:223 HTTP/1.1
> User-Agent: curl/7.38.0
> Host: 192.168.1.101
> Accept: application/json
> Content-Type: application/json
> 
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Sat, 24 Oct 2015 05:33:44 GMT
Date: Sat, 24 Oct 2015 05:33:44 GMT
* Server Apache/2.4.12 (Unix) OpenSSL/1.0.2c is not blacklisted
< Server: Apache/2.4.12 (Unix) OpenSSL/1.0.2c
Server: Apache/2.4.12 (Unix) OpenSSL/1.0.2c
< Content-Length: 0
Content-Length: 0
< Content-Type: text/html;charset=utf-8
Content-Type: text/html;charset=utf-8

< 
* Connection #0 to host 192.168.1.101 left intact

推荐答案

查看工作的浏览器场景在网络上发送的内容将显示类似以下内容:

Looking in to what gets sent on the wire by the working browser scenario would display something like:

192.168.1.101/ckk.cgi?json={%22asking1%22:{%22001%22:%22givnames1%22,%22_id%22:223}}

即JSON部分将进行URL编码(至少部分是).使用--data-urlencode-G标志可以达到相同的效果:

i.e. the JSON part gets URL-encoded (well at least partly). The same effect can by achieved using --data-urlencode and -G flags:

curl -G -v "http://192.168.1.101/ckk.cgi" --data-urlencode 'json={"asking1":{"001":"givnames1","_id":223}}'

这篇关于使用JSON参数对GET进行卷曲.来自服务器的空回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆