0

so I'm trying to use and Arduino Due and a SIM7600 LTE Shield to send a GET request to a server. I've tried multiple servers to no avail and I'm not really sure what I'm doing wrong. Below are my AT commands

19:34:00.607 -> AT+CHTTPACT="website.co.uk",80
19:34:00.710 -> +CHTTPACT: REQUEST
19:34:07.533 -> GET website.co.uk/4gtest.php HTTP/1.0
19:34:12.302 -> Host: website.co.uk
19:34:19.101 -> Content-Length: 42
19:34:28.000 -> 
19:34:28.000 -> OK

And below is the response:

19:34:28.581 -> +CHTTPACT: DATA,295
19:34:28.581 -> http/1.1 400 bad request
19:34:28.581 -> server: nginx
19:34:28.581 -> date: tue, 04 feb 2020 19:34:27 gmt
19:34:28.581 -> content-type: text/html
19:34:28.581 -> content-length: 150
19:34:28.581 -> connection: close
19:34:28.581 -> 
19:34:28.581 -> <html>
19:34:28.581 -> <head><title>400 Bad Request</title></head>
19:34:28.615 -> <body>
19:34:28.615 -> <center><h1>400 Bad Request</h1></center>
19:34:28.615 -> <hr><center>nginx</center>
19:34:28.615 -> </body>
19:34:28.615 -> </html>
19:34:28.648 -> 
19:34:28.648 -> +CHTTPACT: 0

There is definitely an internet connection as it returns custom error pages from the servers but I'm not sure why it can't get the pages I want. Any help would really be appreciated

Thanks

  • 1
    remove website.co.uk from GET – Juraj Feb 04 '20 at 20:26
  • when i try that it doesn't work at all. I get the response +CHTTPACT: 227 which is network error even though i know the network connection is fine –  Feb 04 '20 at 20:44

1 Answers1

0

I've been able to get a server response with the following request:

GET /4gtest.php HTTP/1.1<CR><LF>
Host: website.co.ukCR><LF>
<CR><LF>
<CR><LF>

I got Error 404 response, probably because it was a test page that had currently been removed. Anyway it is not Error 400 response meaning that, at least, the request is not malformed.

Some description about the request:

  1. After GET command, only the path is expected (as correctly suggested by user @juraj's comment)
  2. Since your error response specified HTTP/1.1, I used the same version for my request
  3. The hostname is passed in the line Host: website.co.uk
  4. Please note that each line is terminated with the <CR> + <LF> couple of characters (carriage return, 0x13 ASCII, and line feed, 0x10 ASCII). It is important to specify it because in your question it is not clear how the lines are terminated
  5. Also note that after the last line a double <CR> + <LF> couple terminates the header section of the request

About Content-Length

I have omitted Content-Length field in my request. As brilliantly explained in the answers to this question, this field specifies the number of octects contained in the message body, after the header. But:

  1. The AT command log in your question did not mention any body after the header
  2. As explained in this answer, request bodies in GET requests are not explicitely forbidden, but they are not recommended

Yes, you can send a request body with GET but it should not have any meaning. If you give it meaning by parsing it on the server and changing your response based on its contents, then you are ignoring this recommendation in the HTTP/1.1 spec, section 4.3

Roberto Caboni
  • 6,078
  • 10
  • 19
  • 34
  • Hey, this was really helpful! I've figured out that the issue is the + part. I can't figure out how to send this from arduino code –  Feb 06 '20 at 13:03
  • Talking about your arduino issue, that is another question. Feel free to ask a new question with a good explanation of the issue and linking this one for reference. – Roberto Caboni Feb 06 '20 at 13:13