Chat freely about anything...

User avatar
By rant
#30674 Using the weesp8266 for arudino , i manage to connect via tcp to my server in amazon .

Then trying to send get request ,which works in any browser(and http tool for requests) but NOT in the esp.
Here is the get

Code: Select allGET /http://ec2-xx-xx-xx4-xx.compute-1.amazonaws.com/index.php HTTP/1.1
Host:ec2-52-91-234-18.compute-1.amazonaws.com
User-Agent:runscope/0.1
Content-Type:application/json
Accept-Encoding:gzip,deflate



and here is the code:


Code: Select allchar *hello = "GET /http://ec2-xx-x1-xxx-xx.compute-1.amazonaws.com/index.php HTTP/1.1\r\nHost:ec2-52-91-234-18.compute-1.amazonaws.com\r\nUser-Agent:runscope/0.1\r\nContent-Type:application/json\r\nAccept-Encoding:gzip,deflate\r\n";
    Serial.println(hello);
    wifi.send((const uint8_t*)hello, strlen(hello));
    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");
User avatar
By martinayotte
#30677 The GET request should never include the http prefix and the host, only the path and the header.
So your line of code should be :
Code: Select allchar *hello = "GET /index.php HTTP/1.1\r\nHost:ec2-52-91-234-18.compute-1.amazonaws.com\r\nUser-Agent:runscope/0.1\r\nContent-Type:application/json\r\nAccept-Encoding:gzip,deflate\r\n";
User avatar
By rant
#30686 Thanks. First it didn't worked . Second , if i use http tool such as hurl.it , i can see that the exact same request can work great.
User avatar
By martinayotte
#30693 Of course, hurl.it need the whole thing, but under the hood, it will split things properly, it will first connect, and then send the GET with only the path.
What I've mentioned above is only about the GET syntax.
But in your code, we don't see the whole sketch : Are you doing a "connect" first using IP or server_name along with port number before sending the GET request ?
Also, what is the library you are using for the wifi object ? (because ArduinoESP WifiClient doesn't have send() or recv() method)