|
Senior Member
Join Date: Nov 2014
Location: Brazil
|
02-17-2020
, 16:07
Re: [ANY] SteamWorks
|
#737
|
Quote:
Originally Posted by joao7yt
So, I'm not being able to send a HTTP PUT Request.
Here's my code:
Code:
public Action Event_Round_End_Post(Handle event, const char[]name, bool dontBroadcast)
{
char link[256];
Format(link, sizeof(link), "%s/%s", portal_url, match_id);
char body[512];
Format(body, sizeof(body), "{\"results\": [{\"team\": \"2\", \"score\": %d}, {\"team\": \"3\", \"score\": %d}]}", GetTeamScore(CS_TEAM_T), GetTeamScore(CS_TEAM_CT));
Handle req = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPUT, link);
SteamWorks_SetHTTPRequestHeaderValue(req, "Content-Type", "application/json");
SteamWorks_SetHTTPRequestRawPostBody(req, "application/json", body, sizeof(body));
SteamWorks_SetHTTPCallbacks(req, OnRequestComplete_RoundEnd);
SteamWorks_SendHTTPRequest(req);
}
public int OnRequestComplete_RoundEnd(Handle hRequest, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode)
{
Log("RoundEnd request complete.");
int length;
SteamWorks_GetHTTPResponseBodySize(hRequest, length);
char[] body = new char[length];
SteamWorks_GetHTTPResponseBodyData(hRequest, body, length);
Log("Response:");
Log(body);
}
Here's the response logged:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
I have already tried to log the body and copy it to test using Postman, there it works fine. I have checked and the right header is just "Content-Type", "application/json", and my body is JSON format.
Any help is appreciated.
|
Found my mistake, I was using 'sizeof(body)' instead of 'strlen(body)'...
|
|
|
|