Homebrew [help] I can't use httpc "application/json" 415 The content type, 'application/json,application/x-w

Core_2_Extreme

Well-Known Member
OP
Member
Joined
Feb 11, 2019
Messages
153
Trophies
0
Age
22
XP
1,163
Country
Japan
I making app with httpc.
I got http error :
415 The content type, 'application/x-www-form-urlencoded' is not supported.
https://i.gyazo.com/57f49fcad0b67fcc82e68265299977f0.png

Then I checked api document and it was written "Content-Type application/json"
so I add this code
  • httpcAddRequestHeaderField(&context, "Content-Type", "application/json")
But I got new error
415 The content type, 'application/json,application/x-www-form-urlencoded' is not supported.
https://gyazo.com/53b61e407f0f9b50d12b46851758f43c.png



This is my code.
message_url = "URL";
cache = "Bearer " + acces_token;

httpcOpenContext(&context, HTTPC_METHOD_POST, message_url.c_str(), 0);
httpcSetSSLOpt(&context, SSLCOPT_DisableVerify);
httpcSetKeepAlive(&context, HTTPC_KEEPALIVE_ENABLED);
httpcAddRequestHeaderField(&context, "Connection", "Keep-Alive");
httpcAddRequestHeaderField(&context, "Accept", "application/json");
httpcAddRequestHeaderField(&context, "Content-Type", "application/json");
httpcAddRequestHeaderField(&context, "User-Agent", "v0.0.1");
httpcAddRequestHeaderField(&context, "Authorization", cache.c_str());
httpcAddPostDataRaw(&context, (u32*)data.c_str(), strlen(data.c_str()));
httpcBeginRequest(&context);
httpcGetResponseStatusCode(&context, &code);
httpcDownloadData(&context, buffer_2, 0x1000, &read_size);
httpcCloseContext(&context);
I add "application/json" but always return "The content type, 'application/json,application/x-www-form-urlencoded' is not supported."
How to fix it?
Thankyou.
 
Last edited by Core_2_Extreme,

Core_2_Extreme

Well-Known Member
OP
Member
Joined
Feb 11, 2019
Messages
153
Trophies
0
Age
22
XP
1,163
Country
Japan
I making app with httpc.
I got http error :
415 The content type, 'application/x-www-form-urlencoded' is not supported.
https://i.gyazo.com/57f49fcad0b67fcc82e68265299977f0.png

Then I checked api document and it was written "Content-Type application/json"
so I add this code
  • httpcAddRequestHeaderField(&context, "Content-Type", "application/json")
But I got new error
415 The content type, 'application/json,application/x-www-form-urlencoded' is not supported.
https://gyazo.com/53b61e407f0f9b50d12b46851758f43c.png



This is my code.
message_url = "URL";
cache = "Bearer " + acces_token;

httpcOpenContext(&context, HTTPC_METHOD_POST, message_url.c_str(), 0);
httpcSetSSLOpt(&context, SSLCOPT_DisableVerify);
httpcSetKeepAlive(&context, HTTPC_KEEPALIVE_ENABLED);
httpcAddRequestHeaderField(&context, "Connection", "Keep-Alive");
httpcAddRequestHeaderField(&context, "Accept", "application/json");
httpcAddRequestHeaderField(&context, "Content-Type", "application/json");
httpcAddRequestHeaderField(&context, "User-Agent", "v0.0.1");
httpcAddRequestHeaderField(&context, "Authorization", cache.c_str());
httpcAddPostDataRaw(&context, (u32*)data.c_str(), strlen(data.c_str()));
httpcBeginRequest(&context);
httpcGetResponseStatusCode(&context, &code);
httpcDownloadData(&context, buffer_2, 0x1000, &read_size);
httpcCloseContext(&context);
I add "application/json" but always return "The content type, 'application/json,application/x-www-form-urlencoded' is not supported."
How to fix it?
Thankyou.

Solved
I add this code
//json data
std::string data = "{ \"to\": \"userid\",\"messages\" : [ {\"type\":\"text\",\"text\" : \"hello\"} ] }";]"

httpcAddPostDataRaw(&context, (u32*)data.c_str(), strlen(data.c_str()));
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Xdqwerty @ Xdqwerty: empty chat