0

I want make POST request to parse.com for object creation. This is my code:

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)

I try connecting with different combination of headers but every time I get 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"}

Does some one use parse with node mcu? Where could my problem be?

P.S: Initial working request I get from postman.

ZygD
  • 22,092
  • 39
  • 79
  • 102
once2go
  • 1,452
  • 1
  • 13
  • 21
  • Considering a 401 response I would assume it's a authentication problem. Are you sure your credentials (`Application-Id`, `REST-API-Key`) are correct? – gre_gor Oct 31 '15 at 21:16
  • yep, i'm sure. In P.S part I'm sign that in postman(tools for rest testing) request work fine. Seems to me problem in header composing. – once2go Oct 31 '15 at 21:35
  • 1
    Looks like api.parse.com only works over HTTPS and [SSL doesn't work on NodeMCU](https://github.com/nodemcu/nodemcu-firmware/issues/520). – gre_gor Oct 31 '15 at 23:05
  • looks like that. It's sad – once2go Nov 01 '15 at 08:37
  • There have been recent fixes in the dev branch related to SSL/TLS, maybe give it another try even though parse.com is going to shut down. I suggest you use the [NodeMCU HTTP module](http://nodemcu.readthedocs.org/en/dev/en/modules/http/) which is already available in the dev branch and would greatly simplify your code. Use http://nodemcu-build.com/ to build your own firmware from the dev branch and include the HTTP module. – Marcel Stör Feb 09 '16 at 06:13

1 Answers1

0

Why don't you use a web-service that uses PHP SDK of Parse.com to serve as a middle man to communicate with core of parse. This way you can use POST or GET what ever you want.

Mayur
  • 392
  • 1
  • 3
  • 12
  • It's variant, but looks like workaround for me. Task is produce direct communication with REST. As a variant i can use parse hosting without middle points(services), but it's workaround also. – once2go Nov 01 '15 at 08:40
  • yeah I know its a bit workaround but direct connection with parse is too much of a hassle .. so I just suggested this method – Mayur Nov 01 '15 at 12:07