AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   SteamWorks http request returning weird characters (https://forums.alliedmods.net/showthread.php?t=299773)

SomePanns 07-25-2017 09:40

SteamWorks http request returning weird characters
 
I'm trying to get SteamWorks to read from json data using get requests, but it doesn't matter what URL I use to do it (and I've confirmed its valid json) it always returns weird characters.

PHP Code:

char response_body[4096];

public 
void SendRequest()
{
    
char s_URL[] = "http://httpbin.org/get";
    
char sParam[255] = "123";

    
Handle handle SteamWorks_CreateHTTPRequest(k_EHTTPMethodGETs_URL);

    
SteamWorks_SetHTTPRequestNetworkActivityTimeout(handle5);
    
SteamWorks_SetHTTPRequestHeaderValue(handle"Pragma""no-cache");
    
SteamWorks_SetHTTPRequestHeaderValue(handle"Cache-Control""no-cache");
    
SteamWorks_SetHTTPRequestGetOrPostParameter(handle"action"sParam);
    
SteamWorks_SetHTTPRequestRawPostBody(handle"application/json; charset=utf8;"sParamsizeof(sParam));
    
SteamWorks_SetHTTPCallbacks(handleHTTP_RequestComplete);
    
SteamWorks_SendHTTPRequest(handle);
}

public 
int HTTP_RequestComplete(Handle HTTPRequestbool bFailurebool bRequestSuccessfulEHTTPStatusCode eStatusCode)
{
    if(!
bRequestSuccessful) {
        
PrintToServer("Request failure");
    } else {
        
SteamWorks_GetHTTPResponseBodyData(HTTPRequestresponse_body4096);
        
PrintToServer("response_body = %s"response_body);
        
CloseHandle(HTTPRequest);
    }


And the server always prints this "response_body = UëÕh" which doesn't really make any sense to me.

Leading to this error:
Code:

L 07/25/2017 - 15:32:28: Info (map "ctf_2fort") (file "errors_20170725.log")
L 07/25/2017 - 15:32:28: [SMJSON] Error in line 1, col 1: unable to decode byte 0x89 near 'U'
L 07/25/2017 - 15:32:28: [SM] Exception reported: Invalid <JSON Object> handle 0 (error 4)

Any ideas?

Deathknife 07-25-2017 12:34

Re: SteamWorks http request returning weird characters
 
The length parameter in SteamWorks_GetHTTPResponseBodyData(.., .., length); should be the actual length of response body received and not the max length of your buffer.

PHP Code:

int size;
SteamWorks_GetHTTPResponseBodySize(requestsize);
SteamWorks_GetHTTPResponseBodyData(HTTPRequestresponse_bodysize); 

In that case, I would recommend doing this as well:
PHP Code:

char[] response_body = new char[size]; 



You can also just use SteamWorks_GetHTTPResponseBodyCallback() and not worry about anything above.

SomePanns 07-25-2017 13:59

Re: SteamWorks http request returning weird characters
 
Quote:

Originally Posted by Deathknife (Post 2537689)
You can also just use SteamWorks_GetHTTPResponseBodyCallback() and not worry about anything above.

Didn't realise that was a thing, thank you, solved it!


All times are GMT -4. The time now is 07:36.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.