Raised This Month: $12 Target: $400
 3% 

SteamWorks http request returning weird characters


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SomePanns
Senior Member
Join Date: Dec 2013
Old 07-25-2017 , 09:40   SteamWorks http request returning weird characters
Reply With Quote #1

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?

Last edited by SomePanns; 07-25-2017 at 09:42.
SomePanns is offline
Deathknife
Senior Member
Join Date: Aug 2014
Old 07-25-2017 , 12:34   Re: SteamWorks http request returning weird characters
Reply With Quote #2

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.
__________________
Deathknife is offline
SomePanns
Senior Member
Join Date: Dec 2013
Old 07-25-2017 , 13:59   Re: SteamWorks http request returning weird characters
Reply With Quote #3

Quote:
Originally Posted by Deathknife View Post
You can also just use SteamWorks_GetHTTPResponseBodyCallback() and not worry about anything above.
Didn't realise that was a thing, thank you, solved it!
SomePanns is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:29.


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