我正在嘗試對SMA Datalogger執行HTTP POST請求,該請求使用JSON-RPC來響應HTTP請求。http共享主機POST請求
使用hurl.it我可以做一個成功的請求,例如:
目的地:POST,http://aaa.no-ip.org:101/rpc,執行重定向:對。
標題:Host:aaa.no-ip.org:101,Content-Type:text/plain。
身體:RPC = { 「PROC」: 「GetPlantOverview」, 「格式」: 「JSON」, 「版本」: 「1.0」, 「ID」 爲 「1」}
然後投。它進程的以下要求:
Success
POST http://aaa.no-ip.org:101/rpc
200 OK 401 bytes 3.76 secs
HEADERS
Accept: */*
Accept-Encoding: application/json
Content-Length: 122
Content-Type: text/plain
Host: aaa.no-ip.org
User-Agent: runscope/0.1
BODY
RPC=%7B%22proc%22%3A%22GetPlantOverview%22%2C%22format%22%3A%22JSON%22%2C%22version%22%3A%221.0%22%2C%22id%22%3A%221%22%7D
和響應是:
HEADERS
Cache-Control: no-store, no-cache, max-age=0
Connection: keep-alive
Content-Length: 401
Content-Type: text/html
Date: Wed, 22 Oct 2014 14:15:50 GMT
Keep-Alive: 300
Pragma: no-cache
Server: Sunny WebBox
BODY
{"format":"JSON","result":{"overview":[{"unit":"W","meta":"GriPwr","name":"GriPwr","value":"99527"},{"unit":"kWh","meta":"GriEgyTdy","name":"GriEgyTdy","value":"842.849"},{"unit":"kWh","meta":"GriEgyTot","name":"GriEgyTot","value":"2851960.438"},{"unit":"","meta":"OpStt","name":"OpStt","value":""},{"unit":"","meta":"Msg","name":"Msg","value":""}]},"proc":"GetPlantOverview","version":"1.0","id":"1"}
我的問題是,每次我試圖複製這些請求我總是得到:
string(0) ""
這可能是因爲我在使用共享主機。我試過cURL,普通的PHP(socket和file_get_contents,甚至jQuery) 有人可以請提供一個例子來說明如何做這個請求嗎? jquery或php,我什至不在乎,我一直在嘗試2周,和這麼多的嘗試,無論是我得到的代碼錯誤或只是string(0)""
PS:以前嘗試的例子,參見:https://stackoverflow.com/questions/26408153/solar-energy-monitoring-sma-webbox-json-post-request