在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