View Single Post
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 07-18-2023 , 08:22   Re: REST in Pawn Code Examples
Reply With Quote #117

Quote:
Originally Posted by DJ Tsunami View Post
HTTP

Retrieve an item

PHP Code:
#include <sourcemod>
#include <ripext>

public void OnPluginStart()
{
    
HTTPRequest request = new HTTPRequest("https://jsonplaceholder.typicode.com/todos/1");

    
request.Get(OnTodoReceived);
}

void OnTodoReceived(HTTPResponse responseany value)
{
    if (
response.Status != HTTPStatus_OK) {
        
// Failed to retrieve todo
        
return;
    }

    
// Indicate that the response contains a JSON object
    
JSONObject todo view_as<JSONObject>(response.Data);

    
char title[256];
    
todo.GetString("title"titlesizeof(title));

    
PrintToServer("Retrieved todo with title '%s'"title);

This isn't working. it's not even sending the http request. The function OnTodoReceived is called but with a Null response. The HTTP request is not even reaching the server. The extension on the server is running.

edit: The (php-) api (using get paramters) is working. I was able to call it with the Steamworks extention as well. But I need the Json decoding on the response.

Last edited by fragnichtnach; 07-18-2023 at 08:28.
fragnichtnach is offline