I am currently developing a project where I want esp8266 to send data to Blazor Server App which is hosted on server, but the problem is the Post request to Blazor's server app api keeps returning error code 415.
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
const String ssid="";
const String password="";
const String url="http://raspberrypiproject.com/api/values/1";
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid,password);
Serial.println();
Serial.print("Connecting");
while(WiFi.status()!=WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("Connected to ");
Serial.print(WiFi.SSID());
}
void loop() {
if(WiFi.status()==WL_CONNECTED)
{
WiFiClient client;
HTTPClient http;
if(http.begin(client,url))
{
int code=http.GET();
if(code>0)
{
Serial.println(http.getString());
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
Serial.println(http.POST("hellofromEsp8266"));
}
}
}
}
This is my esp8266 code. In the net I found that the cause of the problem is the Content-Type of "http.addHeader("Content-Type", "application/x-www-form-urlencoded")" and the only change in the response code is when I change it to "multipart/form-data" and it returns error code 400. Is my problem in the client or in Blazor Server.