-->
Page 1 of 2

HTTPS / OAuth Requests

PostPosted: Sun Dec 28, 2014 11:51 pm
by maptor
Somewhat of a lurker here finally coming out to ask for help. :D

Thanks to this site I actually figured out how to get my second ESP up and running. (In my frustration I accidentally fried my first chip when I started to get careless. :( ) I've tried some searches both here and elsewhere, but still haven't found any answers. Hopefully one of you can help me out... here goes nothing:

How do I issue a GET request with authentication? I'm trying to query an API (specifically that belonging to [url]Wit.ai[/url]) but can't seem to get anything more than a 404 or misunderstood request response. At this point I'm literally after nothing more than the formatting of what I need to send to the ESP to make it work.

I can get the board connected to my WiFi network and then successfully connect to the server. But it's everything after
Code: Select allAT+CIPSEND=n
that doesn't seem to work for me. Call me a newbie, but I can't for the life of me figure out how to format my authenticated request and Google really isn't helping me today. :|

Update: So I seem to have figured out how to properly format my request such that the Wit server accepts it. But then I don't receive any data and the ESP unlinks immediately. Might that be because of something I'm doing? This is an example of the HTTP request I'm making (there are carriage returns and newlines between each line as per requirement):

Code: Select allAT+CIPSTART="TCP","54.193.84.116",443
AT+CIPSEND=178
>GET /message?v=20141228&q=how%20many%20lights%20are%20on HTTP/1.1
User-Agent: curl/7.37.1
Host: api.wit.ai
Accept: */*
Authorization: Bearer $My_Token_Here

Re: HTTPS / OAuth Requests

PostPosted: Mon Dec 29, 2014 9:46 am
by pvvx
maptor wrote:
Code: Select allAT+CIPSTART="TCP","54.193.84.116",443
AT+CIPSEND=178
>GET /message?v=20141228&q=how%20many%20lights%20are%20on HTTP/1.1
User-Agent: curl/7.37.1
Host: api.wit.ai
Accept: */*
Authorization: Bearer $My_Token_Here

http://en.wikipedia.org/wiki/Basic_acce ... entication
base64_decode(?)
base64_encode(?)

The end of the header section is indicated by an empty field, resulting in the transmission of two consecutive CR-LF pairs.

Re: HTTPS / OAuth Requests

PostPosted: Mon Dec 29, 2014 5:36 pm
by maptor
pvvx wrote:resulting in the transmission of two consecutive CR-LF pairs.

I didn't have any sort of problems with the formatting of the carriage returns / newlines. I can successfully get to sites and yank HTML pages or text files, its just this very specific application that I am struggling with.

pvvx wrote:base64_encode(?)

They assign keys to use, so I don't need to be making any base-64 computations of my login information for their API. (If you check out their documentation, you'll notice that they do offer examples of calls using cURL https://wit.ai/docs/http/20141022.)

What I was asking for is why I don't seem to be receiving any data. Specifically why it seems as though the ESP unlinks before the JSON reply can be received.

Re: HTTPS / OAuth Requests

PostPosted: Mon Dec 29, 2014 8:58 pm
by pvvx
maptor wrote: Specifically why it seems as though the ESP unlinks before the JSON reply can be received.


Timeout client/server?

AT + CIPSTART does not use SSL. Port 443 = https
google chrome:
Code: Select allhttps://api.wit.ai/message?v=20141022&q=how%20many%20people%20between%20Tuesday%20and%20Friday

Response:
Code: Select allHTTP/1.1 400 Bad Request
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Server: http-kit
Date: Tue, 30 Dec 2014 02:36:06 GMT