Chat here about code rewrites, mods, etc... with respect to the github project https://github.com/esp8266/Arduino

Moderator: igrr

User avatar
By fred.pacc
#32314 Hello,

I would like to send an http request to my domotic server.

when I give my request in my internet browser it works but it asks me a login and password.
but i do not send the request with my arduino codei don't see where i do my password and login in my request.
i use a nodemcu with esp8266

it's my request work in internet browser:

http://admin:password@xx.xxx.xxx.xxx:xx ... me_state=2

Code: [Select]
/*
* This sketch sends data via HTTP GET requests to data.sparkfun.com service.
*
* You need to get streamId and privateKey at data.sparkfun.com and paste them
* below. Or just customize this script to talk to other HTTP servers.
*
*/

#include <ESP8266WiFi.h>

const char* ssid = "*********";
const char* password = "*************";
const char* host = "**.***.***.***";
const char* streamId = "....................";
const char* privateKey = "....................";

void setup() {
Serial.begin(115200);
delay(10);

// We start by connecting to a WiFi network

Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

int value = 0;

void loop() {
delay(5000);
++value;

Serial.print("connecting to ");
Serial.println(host);

// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 50;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}

// We now create a URI for the request


Serial.print("Requesting URL: ");
Serial.println(url);

// This will send the request to the server

client.println("GET /status.sht?Vidage_Ecume_state=1");
delay(10);

// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}

Serial.println();
Serial.println("closing connection");
}


thanks for your help

best regards

fred
User avatar
By lethe
#32321 You need to send an additional HTTP header for basic authentification.
See https://en.wikipedia.org/wiki/Basic_acc ... entication

Also your GET request is malformed, so most servers won't do anything in response. Your request is missing the the HTTP version, a second endline (assuming the arduino library actually uses CRLF ("\r\n") line breaks) and (if you use HTTP 1.1, which you should) the "Host" header.
See https://en.wikipedia.org/wiki/Hypertext ... r_Protocol for an example, how a proper GET request should look.