-->
Page 1 of 6

Skip HTTP Header from GET request

PostPosted: Tue Aug 30, 2016 8:46 pm
by Luiz Henrique
Sorry for wrong topic

I need help with my project. Here is my code:

Code: Select allvoid ConexaoServer(){
    uint8_t buffer[1024] = {0};

    if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
        Serial.print("Conexao com o Host OK!\r\n");
    } else {
        Serial.print("Conexao com o Host com ERRO!\r\n");
    }

    char *ComandoGET = "GET /teste HTTP/1.1\r\nHost: SmartHome\r\nConnection: close\r\n\r\n";
    wifi.send((const uint8_t*)ComandoGET, strlen(ComandoGET));

    uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
    if (len > 0) {
        Serial.print("Received:[");
        for(uint32_t i = 0; i < len; i++) {
            Serial.print((char)buffer[i]);
        }
        Serial.print("]\r\n\r\n");
    }
}


And i receive from Node.js in Serial

Code: Select allReceived:[HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 4
ETag: W/"4-wArb1VtkpsN6In8g50pGNw"
Date: Wed, 31 Aug 2016 01:26:41 GMT
Connection: close

Luiz]


But i want to receive just "Received:[Luiz]". How i can do this?

Thanx!

Re: Skip HTTP Header from GET request

PostPosted: Wed Aug 31, 2016 8:17 am
by martinayotte
The header response always ends with this blank empty line, so you only need to throw away any lines before this first empty line.

Re: Skip HTTP Header from GET request

PostPosted: Wed Aug 31, 2016 9:43 am
by Luiz Henrique
martinayotte wrote:The header response always ends with this blank empty line, so you only need to throw away any lines before this first empty line.


Hmmm, i undertood, but this library is the best in my case? Do u have a Example Code for that?

Re: Skip HTTP Header from GET request

PostPosted: Wed Aug 31, 2016 10:40 am
by martinayotte
It has nothing with a library.
You simply need to create a for loop that will skip the unneeded characters until you find "\r\n\r\n" substring.
It can be done with something like (untested):
Code: Select allchar *ptr = buffer;
int len = strlen(buffer);
for (int = 0; i < len; i++) {
    if (strncmp(ptr++, "\r\n\r\n", 4) == 0) break;
}
ptr += 3;
Serial.println(ptr);