-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTPResponse.Data throws exception "Invalid JSON" #63
Comments
Show the code and full endpoint. It looks like you incorrect build the link. |
@CrazyHackGUT Hello, thanks for answering. Full code here, with screenshots also with the JSON sent to the endpoint. void get_player_info(int client) {
GetClientName(client, g_players[client].name, sizeof(CSGOPanelUser::name));
GetClientAuthId(client, AuthId_SteamID64, g_players[client].steam_id, sizeof(CSGOPanelUser::steam_id));
JSONObject json = new JSONObject();
json.SetString("token", TOKEN);
json.SetInt("server_id", SERVERID);
json.SetString("steamid", g_players[client].steam_id);
if (DEBUG) {
char debugjson[MAX_DEBUG_LENGTH];
json.ToString(debugjson, sizeof(debugjson), JSON_INDENT(5));
LogMessage("\n@ get_player_info @ sending api request to \"%s\":\n%s\n", "https://api.csgopanel.com/get/gametracker", debugjson);
}
HTTPRequest req = new HTTPRequest("https://api.csgopanel.com/get/gametracker");
req.SetHeader("Content-Type", "application/json");
req.Post(json, httpcallback_getgametracker, GetClientUserId(client));
delete json;
}
public void httpcallback_getgametracker(HTTPResponse response, any userid, const char[] error) {
int client = GetClientOfUserId(userid);
if (!(IsClientConnected(client) && !IsFakeClient(client) && !IsClientSourceTV(client))) {
return;
}
if (response.Status != HTTPStatus_OK && response.Status != HTTPStatus_Created) {
LogError("\nError on request \" get/gametracker \" (%i)\nError: %s", response.Status, error);
return;
}
LogMessage("\n client exists... lets get his data %i \n", response.Status);
JSONObject user_data = view_as<JSONObject>(response.Data); // ERROR, function stops here.
if (DEBUG) {
char debugjson[MAX_DEBUG_LENGTH];
user_data.ToString(debugjson, sizeof(debugjson), JSON_INDENT(5));
LogMessage("\n@ httpcallback_getgametracker @ received player data:\n%s\n", debugjson);
}
} |
Could you try the debug build posted here, and post the output from the server console? |
Hello @ErikMinekus , yes sure. public void OnClientAuthorized(int client, const char[] auth) {
if (!IsFakeClient(client)) {
get_player_info(client);
}
}
void get_player_info(int client) {
char name[64];
char steam_id[64];
GetClientName(client, name, sizeof(name));
GetClientAuthId(client, AuthId_SteamID64, steam_id, sizeof(steam_id));
JSONObject json = new JSONObject();
json.SetString("token", TOKEN);
json.SetInt("server_id", SERVERID);
json.SetString("steamid", steam_id);
if (DEBUG) {
char debugjson[MAX_DEBUG_LENGTH];
json.ToString(debugjson, sizeof(debugjson), JSON_INDENT(5));
LogMessage("\n@ get_player_info @ sending api request to \"%s\":\n%s\n", "https://api.csgopanel.com/get/gametracker", debugjson);
}
HTTPRequest req = new HTTPRequest("https://api.csgopanel.com/get/gametracker");
req.SetHeader("Content-Type", "application/json");
req.Post(json, httpcallback_getgametracker, GetClientUserId(client));
delete json;
}
public void httpcallback_getgametracker(HTTPResponse response, any userid, const char[] error) {
int client = GetClientOfUserId(userid);
if (response.Status != HTTPStatus_OK && response.Status != HTTPStatus_Created) {
LogError("\nError on request \" get/gametracker \" (%i)\nError: %s", response.Status, error);
return;
}
JSONObject user_data = view_as<JSONObject>(response.Data); // CRASH, function stops here.
if (DEBUG) {
char debugjson[MAX_DEBUG_LENGTH];
user_data.ToString(debugjson, sizeof(debugjson), JSON_INDENT(5));
LogMessage("\n@ httpcallback_getgametracker @ received player data:\n%s\n", debugjson);
}
} |
Hi @ErikMinekus, we do have a similar issue (https://github.com/ESK0/eItems/blob/main/scripting/files/parse.sp#L43) basically we have found out that this happen on Windows only and only if the endpoint is https, http works just fine.
|
Yes, it’s an issue with HTTP/2 on Windows. HTTP/2 is only attempted over HTTPS. |
Is there a workaround? |
Use SteamWorks extension and convert body to JSON via |
This can be inconvenient for many people (install another extension)... but probably the fastest solution at the moment. |
Hello.
Im trying something and I cannot understand if its my code or the extension that is not working as it should.
Im doing an API request where it should return me some JSON data. The problem is, Im getting some errors:
(but sometimes error message is different) :
This is my code (where the exception occurs).
I do not understand the error because, testing this endpoint on a software like Postman, it gives me valid JSON
Example:
Setup:
1.3.1 (latest)
css
1.10.0.6510
windows
Thanks in advance.
The text was updated successfully, but these errors were encountered: