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

Parents
  • Hello Shivek,

    Shivek said:
    Another thing is AT#HTTPCREQ is working for me, when I am using only one header field ending with <CR> <LF>. When I am using multiple header fields ending with <CR> <LF>, its not working for me.

    I’m still a little bit unsure about the request-URI string you are using. “?page=1” is a query component, and I’m not quite sure if it can be separated with a “/”. Are you able to use the same string with only one header field?

    Regards,

    Markus

  • Hi Markus,

    I got this working after troubleshooting it by forwarding the request to a local IP and using Python script to process the incoming request to the server. 

    I am posting my solution so that it can help others and save their time. 

    I removed the Host header field and the extra <CR><LF> pair which I was using to separate the header fields and payload. Another noticeable thing is the content length should be the number of characters we want to send without <CR><LF>. To be more clear following is the POST request that worked for me:

    AT#XHTTPCREQ="POST","/iot/","Authorization: Basic ZGVtbzpkxxxx
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 65
    ",65

    And send payload after you receive "#XHTTPCREQ: 1" from the modem/nRF9160. My payload looked like this:

    text=0001,0,2021,9,8,10,4,29,20014xxxx,23.500,1.000,2.200,3.900,

    Thanks for your efforts Markus.

    Regards,

    Shivek

Reply
  • Hi Markus,

    I got this working after troubleshooting it by forwarding the request to a local IP and using Python script to process the incoming request to the server. 

    I am posting my solution so that it can help others and save their time. 

    I removed the Host header field and the extra <CR><LF> pair which I was using to separate the header fields and payload. Another noticeable thing is the content length should be the number of characters we want to send without <CR><LF>. To be more clear following is the POST request that worked for me:

    AT#XHTTPCREQ="POST","/iot/","Authorization: Basic ZGVtbzpkxxxx
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 65
    ",65

    And send payload after you receive "#XHTTPCREQ: 1" from the modem/nRF9160. My payload looked like this:

    text=0001,0,2021,9,8,10,4,29,20014xxxx,23.500,1.000,2.200,3.900,

    Thanks for your efforts Markus.

    Regards,

    Shivek

Children
No Data
Related