在Lua程序中,使用modeMCU,我遇到了一個HTTP POST請求的問題。使用json的原始POST請求
我測試我的請求對httpbin.org/post
。
我想給JSON數據,所以我的要求是:
POST /post HTTP/1.1
Host: httpbin.org
Connection: close
Accept: */*
User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)
Content-Type: application/json
{...some JSON here}
的迴應是:
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 07 Sep 2015 10:39:12 GMT
Content-Type: application/json
Content-Length: 332
Connection: close
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)"
},
"json": null,
"origin": "5.51.195.252",
"url": "http://httpbin.org/post"
}
我已經嘗試過其他2語法對我的身體:
POST /post HTTP/1.1
Host: httpbin.org
Connection: close
Accept: */*
User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)
Content-Type: application/json
json:{...some JSON here}
and
POST /post HTTP/1.1
Host: httpbin.org
Connection: close
Accept: */*
User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)
Content-Type: application/json
"json":"{...some JSON here}"
沒有工作...
你有什麼想法嗎?
注:當我使用curl -v -d @somejson.json -H "Content-Type: application/json" -i -v "http://httpbin.org/post"
它的工作原理,但我不能讓原始請求
你有沒有嘗試在您的POST請求中添加「Content-Length」標題? – mpromonet
而且...是的,這是解決方案(經過幾個小時的調試後,我自己昨天發現)謝謝! – bixente57
歡迎您!如果它能解決您的問題,那麼您發佈答案可能會很好,也很有幫助。 – mpromonet