【发布时间】:2015-12-02 21:40:14
【问题描述】:
在使用 modeMCU 的 Lua 程序中,我的 HTTP 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}
和
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标头? -
而且...是的,这就是解决方案(我昨天经过数小时的调试后找到的)谢谢!
-
欢迎您!如果它解决了您的问题,那么您发布您的答案可能会很有帮助。
标签: json http curl lua http-post