AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Extensions (https://forums.alliedmods.net/forumdisplay.php?f=134)
-   -   REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22) (https://forums.alliedmods.net/showthread.php?t=298024)

mrdiega 10-04-2021 17:18

Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22)
 
can i use it with sv_hibernate_when_empty 1?
(plugin !stickers)

kratoss1812 12-04-2021 15:48

Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22)
 
Hi, please add "GetDataType". Thanks <3

Stewart Anubis 01-25-2022 15:03

Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22)
 
Does anyone know how I can convert this "[[["Hola","hello",null,null,10]],null,"en",null,null,null,null,[]]" to "Hola" using #include <ripext> ?

Code:

Handle CreateRequest(char[] input, char[] target)
{
   
    Handle request = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, "http://translate.googleapis.com/translate_a/single");
    SteamWorks_SetHTTPRequestGetOrPostParameter(request, "client", "gtx");
    SteamWorks_SetHTTPRequestGetOrPostParameter(request, "dt", "t");   
    SteamWorks_SetHTTPRequestGetOrPostParameter(request, "sl", "auto");//from en default, so you might wanna add this param too to modify.
    SteamWorks_SetHTTPRequestGetOrPostParameter(request, "tl", target);//to desired.. target language
    SteamWorks_SetHTTPRequestGetOrPostParameter(request, "q", input);//input text

    //final url would be something like this  https://translate.googleapis.com/tra...&tl=es&q=hello
    //response example [[["Hola","hello",null,null,10]],null,"en",null,null,null,null,[]]  so we need to parse json on Callback_OnHTTPResponse >  JSON.parse(response)[0][0][0] = Hola
   
    Handle datapack = CreateDataPack();
    WritePackString(datapack, target);
    WritePackString(datapack, input);

   
    SteamWorks_SetHTTPRequestContextValue(request, datapack);
    SteamWorks_SetHTTPCallbacks(request, Callback_OnHTTPResponse);
    return request;
}

public int Callback_OnHTTPResponse(Handle request, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode, Handle datapack)
{
        if (!bRequestSuccessful || eStatusCode != k_EHTTPStatusCode200OK)
        {         
                CloseHandle(datapack);               
                return;
        }

        int iBufferSize;
        SteamWorks_GetHTTPResponseBodySize(request, iBufferSize);

        char[] result = new char[iBufferSize];
        SteamWorks_GetHTTPResponseBodyData(request, result, iBufferSize);
        delete request;
       
        char target[3], input[255];
        ResetPack(datapack);
        ReadPackString(datapack, target, 3);
        ReadPackString(datapack, input, 255);
        CloseHandle(datapack);

        PrintToServer(result); // = [[["Hola","hello",null,null,10]],null,"en",null,null,null,null,[]]
}


leandro442 08-10-2022 14:11

Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22)
 
hello, I was trying to create a header through ripext on a test site but nothing happens I don't know why, has anyone created a header and did it work? do we have to give some permission or create code type in index.php? to work?

bayshades 11-17-2022 22:59

Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/06/06)
 
Quote:

Originally Posted by digin (Post 2750465)
i don't know why but after i move to my new VPS the PUT think is not working, always return HTTPStatus_Invalid = 0.

My Old VPS : Plesk Panel (PHP 7.4.20 + Server API FPM/FastCGI)
My New VPS : Cyberpanel (PHP 7.4.20 + Server API LiteSpeed V7.9)

"REST in Pawn" (1.2.3) by Tsunami: Provides HTTP and JSON natives for plugins

i test with Postman it's working, but the plugin always return HTTPStatus_Invalid = 0.

anyone experiencing the same thing?

I am facing with same issue. Does anyone found a way to fix it?

foxhound27 03-21-2023 15:03

Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22)
 
amazing, thx

fragnichtnach 07-18-2023 08:22

Re: REST in Pawn Code Examples
 
Quote:

Originally Posted by DJ Tsunami (Post 2524661)
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.


All times are GMT -4. The time now is 10:12.

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