cancel
Showing results for 
Search instead for 
Did you mean: 

HTTPPOST Example Android GCM

florian239955_st
Associate II
Posted on March 23, 2015 at 13:57

Hi All,

I'm evaluating the SPWF01, so I want to send an Android GCM HTTP post (json or plain text) - but I've no success.

I tried it with:

AT+S.HTTPPOST=android.googleapis.com,/gcm/send,Content-Type:application/x-www-form-urlencoded;charset=UTF-8&Authorization:key=APIKEY,80

and also with:

AT+S.HTTPPOST=android.googleapis.com,/gcm/send,Content-Type:application/json&Authorization:key=APIKEY,80

I got following answer:

HTTP/1.0 401 Unauthorized

Has anybody an idea or can give me an example how to send the http header via the SPWF AT command?

Best regards,

Flo

#http-post #spwf #gcm
20 REPLIES 20
Posted on March 23, 2015 at 19:42

Hi Flo,

Content-Type is statically and automatically added by AT-command itself.

You need to write only address, path to cgi/php/other engine, and form content (in form ''name=value[&]''). Default port is 80.

Example: at+s.httppost=posttestserver.com,/post.php,name=demo&email=mymail&subject=subj&body=message

Can I help you somehow?

Ciao

jerry

florian239955_st
Associate II
Posted on March 25, 2015 at 11:35

Hi Jerry,

thank you for your answer.

Poorly, I still don't get it.

Do you have another example for me, for example a command with a header information for an Android GCM request:

https://developer.android.com/google/gcm/http.html

The request contains two parts:

- HTTP Header --> Authorization & Content Format

- HTTP Body --> Data

If no content format is transmitted, plain text will be used instead of JSON. So I tried

AT+S.HTTPPOST=android.googleapis.com,/gcm/send,name=Authorization:key=APIKEY,80

How can I tell the application, that the message of the body is in JSON format?

That would be a nice example for the ''Wifi Training - Hands on'' ;) Also sending an email via smtp would be another very nice example for evaluation the module ;)

Kind regards,

Flo

Posted on March 25, 2015 at 15:26

Hi Flow,

I got your point. Since surrent ''content type'' is statically added, and since you need a ''custom'' content type, standard HTTP command is not suitable for you.

Maybe a '',content-type'' parameter is enough in standart HTTP command to set a ''custom'' content type. I mean, moving from ''address,path,form-content, port'' to  ''address,path,form-content,port,content-type''.

Is this what you are looking for?

In the meanwhile, you could use basic sockets in place of high level HTTP commands:

1 - open a socket

2 - write request

3 - wait for WIND:55 indicator

4 - wait for WIND:58 indicator, if any

5 - read web server reply

Is this working?

About SNMP, thanks for suggesion.

Ciao

jerry

florian239955_st
Associate II
Posted on April 02, 2015 at 22:29

Hi Jerry,

thank you for your hint. Unfortunately, I still don't get it.

I will wait for the release of the next firmware version unitl I spend more work in this. But if anyone has a solution, I will test it before ;)

buona notte,

Flo
Posted on April 03, 2015 at 15:05

Hi Flow,

I'm not an expert on this kind on stuff, but I'm almost sure that, once socket is opened with server, you can do whatever you want.

Be sure on target address (

gcm.googleapis.com?

) and port (

5235?

), and try to write proper http requests.

Note that FW release will contain also TLS/SSL secure layer. HTTPS can also be used.

ciao

j

Posted on October 06, 2015 at 09:13

Hi all,

I have a same problem. How can I specify Content-Type in AT-command

AT+S.HTTPPOST

?

I used:

at+s.httppost=192.168.1.53,/events.aspx,application/x-www-form-urlencodedt=subj&body=message

Modul began to use -

application/x-www-form-urlencoded

  as Content-Type.

And modul use this  

application/x-www-form-urlencoded

  as Content-Type after switch off.

Could you help me, plz?

Posted on October 06, 2015 at 09:17

Hi Sergey,

using current FW release, the only possibility is to open a socket and manage custom http request by SOCKW command.

Next FW release will allow to solve this current limit. Stay tuned :)

j

Posted on October 06, 2015 at 10:31

Hi, Gallucci.

Thank you. I used last FW 3.4.

When can I wait for new FW?

kecskesgery
Associate II
Posted on November 06, 2015 at 16:36

Hello there!

@Flow: I'm kinda in the same boat as you were some month ago. Did you find any solution to your problem? I'm dying to hear it, 'cuz I'm kinda stuck, like you were.

Regards.