0

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.

2
  • 1
    the x-www-form-urlencoded requires name=value format. the multipart format has its required syntax too Commented Aug 30, 2022 at 14:54
  • Read HTTP POST to understand how HTTP POST actually composed. Commented Aug 31, 2022 at 0:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.