我有一個curl
命令的問題。我想要發送請求(GET)與JSON參數,我應該從服務器得到一些答案,但不幸的是我沒有得到。 在最好的情況下,我得到以下答案表格服務器使用JSON參數進行卷曲GET。來自服務器的空回覆
* 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
我閱讀以下內容:
Curl GET request with json parameter How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?
所以我tryed以下命令
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}}"
所有命令不起作用....
工程在瀏覽器的命令就是:
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
我建議正確%的轉義參數值的網址,例如:可以通過使用
--data-urlencode
和-G
標誌達到同樣的效果。 '192.168.1.101/ckk.cgi?json=%7B"asking1"%3A%7B"001"%3A" givnames1「,」_ id「%3A223%7D%7D'(冒號和開啓/關閉花括號逃脫)。 [RFC 3986](https://tools.ietf.org/html/rfc3986)是相關標準。 – collapsar我嘗試'curl -v -H「Accept:application/json」-H「Content-type:application/json」-X GET -d'%7B「ask1」%3A%7B「001」%3A「givnames1」 ,「_id」%3A223%7D%7D'http:// 192.168.1.101/ckk.cgi'然後我得到了和上面相同的答案,並且只嘗試了'curl 192.168.1.101/ckk.cgi?json=% 7B「ask1」%3A%7B「001」%3A「givnames1」,「_id」%3A223%7D%7D'然後我什麼也沒得到。 – Mbded
下一次嘗試使用'curl -vvv'。它將提供非常詳細的輸出,可能會幫助您找到解決方案。 – Daniel