Skip to main content
florian239955_st
Associate III
March 23, 2015
Question

HTTPPOST Example Android GCM

  • March 23, 2015
  • 20 replies
  • 2669 views
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
    This topic has been closed for replies.

    20 replies

    Gerardo GALLUCCI
    ST Employee
    March 23, 2015
    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 III
    March 25, 2015
    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

    Gerardo GALLUCCI
    ST Employee
    March 25, 2015
    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 III
    April 2, 2015
    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
    Gerardo GALLUCCI
    ST Employee
    April 3, 2015
    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

    stm239955_stm1_stmicro_com
    Visitor II
    October 6, 2015
    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?

    Gerardo GALLUCCI
    ST Employee
    October 6, 2015
    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

    stm239955_stm1_stmicro_com
    Visitor II
    October 6, 2015
    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 III
    November 6, 2015
    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.

    florian239955_st
    Associate III
    November 9, 2015
    Posted on November 09, 2015 at 17:24

    Hi Gergely,

    no, I'm still waiting for an update and didn't spend more time in solving this.

    Meanwhile, I regret choosing the ST module. The firmware seems to be still in development...

    With the microchip RN171 module I send the GCM request without problems. Maybe I will go back to that module...

    Regards,

    Flow