ESP8266客户端连接到MongoDB
我试图向我的MongoDB(实际的CouchDB)发布一条新记录,但似乎我的请求格式有问题。
我使用下面的代码:(不显示调试和验证)
WiFiClient client;
client.connect("172.16.1.4", 5984)
String connStr = "POST /iot/ HTTP/1.1rn"
            "Host: user:password@172.16.1.4:5984/ rn"
            "Content-Type: application/jsonrn"
            "rn"
            "'{"a":1}'rnrn";
client.print(connStr);
我得到这个回应:
  HTTP / 1.1 400错误请求 
  服务器:CouchDB / 1.6.1(Erlang OTP / 18) 
  日期:2017年十月07日星期六11:57:50 GMT 
  内容类型:text / plain;  字符集= utf-8的 
  内容长度:48缓存控制:必须重新验证 
{ “错误”: “BAD_REQUEST”, “理由”: “invalid_json”}
  HTTP / 1.1 400不好 
  请求服务器:MochiWeb / 1.0(你们中的任何一个获得了smint?) 
  日期:2017年十月07日星期六11:57:50 GMT 
  内容长度:0 
我尝试过使用不同的json / data ...
使用Linux - 我没有问题:
curl -X POST用户:password@172.16.1.4:5984 / iot / -H“Content-Type:application / json”-d'{“a”:3}'
这个问题可能与{}和{}之前的单引号(')
代替
 "'{"a":1}'rnrn"
它应该是
 "{"a":1}rnrn"
我错过了这一行:
"Content-Length: " + String(json.length()) + "rn"
在标题中。
链接地址: http://www.djcxy.com/p/48553.html上一篇: ESP8266 client connection to MongoDB
下一篇: Which directory should I place my json file, in order to import it into couchdb
