This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Format for HTTP request using AT commands in SLM application

Hi,

I am  trying to retrieve data from server using HTTP GET request, using AT command for Serial LTE modem application.

So, I can connect to the server using AT#XHTTPCCON command, but not able to get the data from the server. Here is the format for HTTP request I am sending to the nRF91600 over UART using nRF Connect v 3.7.0.

AT#XHTTPCREQ="GET","/instruments/150771004/temperature-values/?page=1 HTTP/1.1","Host: demo.abc.com\r\nAccept: application/vnd.api+json\r\nAuthorization: Basic ZGVtbzpkZxxx\r\n"

I put abc.com and xxx here in the Host and Authorization fields just because of company policy. 

The server is responding with 400 bad request error.

Can you please let me know if I am missing something in the header field format?

I have checked on the server side, and I can see upto the resource field (up to HTTP/1.1), its in correct format. So, I am guessing there is something to do with header field of the command.

I couldn't find any example from Nordic what should be the format if there is any header field in the HTTP request, i.e., for authorization etc.

I tried to get the SLM application in debug mode and I could see its getting the proper string for httpc.headers variable in handle_AT_HTTPC_REQUEST function of the slm_at_httpc.c source file.

I am using nRF Connect v 3.7.0, nRF Connect SDK v1.4.1, in software tools and nRF9160DK for the hardware.

Looking forward for a prompt response.

Regards,

Shivek

  • Hello Shivek,

    Only in C language "\r\n" is understood as <CR><LF>. HTTP payload is sent as raw data so there should be raw CR and LF, which in your case should look like this:

    AT#XHTTPCREQ="GET","/instruments/150771004/temperature-values/?page=1 HTTP/1.1","Host: demo.abc.com
    Accept: application/vnd.api+json
    Authorization: Basic ZGVtbzpkZxxx
    "

    The following example in the SLM documentation demonstrates the usage as well. I hope this will solve your issue!

    Regards,

    Markus

  • Thanks for your response Markus, but I already have tried with hex values for nrf Link monitor i.e., \x0D for <CR> and \x0A for <LF>. And it understand those very well. I am saying that because I can see on the console screen. So, for the command below

    AT#XHTTPCREQ="GET","/instruments/150771004/temperature-values/?page=1  HTTP/1.1","Host: demo.abc.com\x0D\x0AAccept: application/vnd.api+json\x0D\x0AAuthorization: Basic ZGVtbzpkZxxx\x0D\x0A"

    It shows like this:

    AT#XHTTPCREQ="GET","/instruments/150771004/temperature-values/?page=1  HTTP/1.1","Host: demo.abc.com
    
    
    
    
    Accept: application/vnd.api+json
    
    
    
    
    Authorization: Basic ZGVtbzpkZxxx

    "

    This I have copied and pasted from the console in Link Monitor app after the command is sent.

    Would you please give me some demo using Link monitor for a HTTP request incorporating more than one header fields?
    That would be really helpful as I would be able to see what exactly has to be done.

    Regards,
    Shivek
  • Oops! The UI has done something with my response. So, basically this is what I can see:

    AT#XHTTPCREQ="GET","/instruments/150771004/temperature-values/?page=1  HTTP/1.1","Host: demo.yieldpoint.com

    Accept: application/vnd.api+json

    Authorization: Basic ZGVtbzpkZW1v

    "

  • Thanks a lot for your feedback, Shivek!

    Shivek said:
    And it understand those very well.

    Yes, the LTE Link Monitor should convert this to the right raw data format.

    Could you remove the "HTTP/1.1" part and check if that makes any difference?

    AT#XHTTPCREQ="GET","/instruments/150771004/temperature-values/?page=1","Host: demo.abc.com\x0D\x0AAccept:
    application/vnd.api+json\x0D\x0AAuthorization: Basic ZGVtbzpkZxxx\x0D\x0A"

    I am using nRF Connect v 3.7.0, nRF Connect SDK v1.4.1, in software tools and nRF9160DK for the hardware.

    I would strongly recommend update to at least NCS v1.5.0. There is some instability with the SLM application in earlier versions.

    Regards,

    Markus

  • Hi Markus, 

    I already have tried to remove HTTP/1.1 part. But its the same "400 bad request" response I am getting from the server. 

    As I asked in previous post, would you be able to give some demo with HTTP request having more than one header fields?

    Furthermore, what if I change the command termination settings to '\0' character? I doubt that the error probably is due to default setting of <CR><LF>, as there are fields in HTTP request which needs to be terminated by <CR><LF>. Below is the screenshot of the termination mode settings:

    Also, Link monitor will append the command with <CR><LF> automatically, is there anyway to change this feature in Link Monitor app?

    In the mean time I would try with the latest sdk and will get back to you.

    Regards,

    Shivek

Related