我想向 parse.com 发出 POST 请求以创建对象。这是我的代码:
sk=net.createConnection(net.TCP, 0)
addr=""
sk:dns("api.parse.com",function(conn,ip) addr=ip end)
print(addr)
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end )
conn:on("connection", function(c)
conn:send("POST /1/classes/TestClass2 HTTP/1.1\r\n"
.."Host: api.parse.com\r\n"
.."X-Parse-Application-Id: 1***whq****************oJFzu43nIO**rzh\r\n"
.."X-Parse-REST-API-Key: 6Y***QPSQ****************bgzIhxYqG**OsfY\r\n"
.."Content-Type: application/json\r\n"
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
end)
conn:connect(80, addr)
我尝试使用不同的标题组合进行连接,但每次我收到 401 ERROR
HTTP/1.1 401 Unauthorized
Access-Control-Allow-Methods: *
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=utf-8
Date: Sat, 31 Oct 2015 18:05:11 GMT
Server: nginx/1.6.0
Www-Authenticate: Basic realm="Parse"
X-Parse-Platform: G1
X-Runtime: 0.015377
Content-Length: 25
Connection: keep-alive
{"error":"unauthorized"}
有人使用 parse 和 node mcu 吗?我的问题可能出在哪里?
PS:我从邮递员那里得到的初始工作请求。