Skip to content

Bad HTTP response #11375

Closed
Closed
@ITstreet1

Description

@ITstreet1

Board

ESP32 C3

Device Description

Devkit

Hardware Configuration

Nothing

Version

latest stable Release (if not listed below)

IDE Name

Arduino IDE

Operating System

Win10

Flash frequency

80MHz

PSRAM enabled

no

Upload speed

921600

Description

I tried to use my older code but always get a bad HTTP response. Can someone point me what to change?
The URL is ok, as I get the valid data over the browser with HTTP code 200.

Sketch

#include <WiFi.h>
#include <HTTPClient.h>
WiFiClient client;

const char* ssid = "SSID";
const char* password = "PASS";
const int deviceID = 2;
String server = "www.somesite.com";

void setup(){
  Serial.begin(9600);
  Serial.println();
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while((WiFi.status() != WL_CONNECTED)) { 
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("Connected!");

}
void loop(){
  Serial.println("test");
  if(WiFi.status()== WL_CONNECTED){
      HTTPClient http;
      String serverPath = server;
      Serial.println(serverPath);
      Serial.println("-----");
      http.begin(client, serverPath.c_str());
      int httpResponseCode = http.GET();
      if(httpResponseCode>0){
        Serial.print("HTTP Response code: ");
        Serial.println(httpResponseCode);
      }else{
        Serial.print("Error code: ");
        Serial.println(httpResponseCode);
      }
      http.end();
    }else{
      Serial.println("WiFi Disconnected");
    }
  delay(5000);
}

Debug Message

I always get -1 as HTTP code. Verbose output this:

[  6031][V][HTTPClient.cpp:259] beginInternal(): url: www.somesite.com
[  6315][D][HTTPClient.cpp:314] beginInternal(): protocol: http, host: www.somesite.com port: 80 url: ....//link is not important
[  6505][D][HTTPClient.cpp:621] sendRequest(): request type: 'GET' redirCount: 0

[  6593][D][NetworkManager.cpp:83] hostByName(): Clearing DNS cache
[  6670][D][NetworkManager.cpp:127] hostByName(): DNS found IPv4 *****
[  6776][E][NetworkClient.cpp:293] connect(): Setsockopt 'SO_SNDTIMEO'' on fd 48 failed. errno: 22, "Invalid argument"
[  6901][D][HTTPClient.cpp:1248] connect(): failed connect to www.somesite.com:80
[  6983][W][HTTPClient.cpp:1604] returnError(): error(-1): connection refused
Error code: -1
[  7066][D][HTTPClient.cpp:434] disconnect(): tcp is closed

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions