Raised This Month: $32 Target: $400
 8% 

Solved I need a library to encode as JSON and HTTP POST, GET


Post New Thread Reply   
 
Thread Tools Display Modes
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-06-2022 , 05:53   Re: I need a library to encode as JSON and HTTP POST, GET
Reply With Quote #11

If you want compatibolity with 1.8.2, yes, you can not use any 1.9 specific features.

You may search for 3rd party modules that implement the 1.9 functionality you were looking for. For example, there are a few json modules here that may be a good replacement for the json functionality in 1.9.
__________________
HamletEagle is offline
ghostdlr
Senior Member
Join Date: Aug 2010
Old 11-06-2022 , 09:54   Re: I need a library to encode as JSON and HTTP POST, GET
Reply With Quote #12

Quote:
Originally Posted by HamletEagle View Post
If you want compatibolity with 1.8.2, yes, you can not use any 1.9 specific features.

You may search for 3rd party modules that implement the 1.9 functionality you were looking for. For example, there are a few json modules here that may be a good replacement for the json functionality in 1.9.
Can you suggest me something?

I found this but it has no proper documentation and I can't get it to work for what I need:
https://forums.alliedmods.net/showthread.php?t=189772
ghostdlr is offline
Levenus Supremus
Junior Member
Join Date: Jan 2012
Location: St.Petersburg
Old 11-10-2022 , 09:57   Re: I need a library to encode as JSON and HTTP POST, GET
Reply With Quote #13

I recommend using AmxxEasyHttp instead of AmxxCurl, it is much easier to use.
https://github.com/Next21Team/AmxxEasyHttp

First of all, use json_decode to get a JSON handle and then use json_get_...
Levenus Supremus is offline
sebxx4
Senior Member
Join Date: Feb 2013
Old 11-14-2022 , 01:59   Re: I need a library to encode as JSON and HTTP POST, GET
Reply With Quote #14

Maybe gRIP?
https://github.com/In-line/grip
sebxx4 is offline
ghostdlr
Senior Member
Join Date: Aug 2010
Old 11-23-2022 , 13:04   Re: I need a library to encode as JSON and HTTP POST, GET
Reply With Quote #15

Quote:
Originally Posted by Levenus Supremus View Post
I recommend using AmxxEasyHttp instead of AmxxCurl, it is much easier to use.
https://github.com/Next21Team/AmxxEasyHttp

First of all, use json_decode to get a JSON handle and then use json_get_...
I'm getting some errors when I try the example code for http get:

===== include\easy_http.inc =====
WARNING [28]: symbol "EZH_SSL_REMOTE_CERTIFICATE_ERRO" is truncated to 31 characters
WARNING [67]: symbol "ezhttp_option_set_connect_timeo" is truncated to 31 characters
WARNING [72]: symbol "ezhttp_option_set_plugin_end_be" is truncated to 31 characters

===== plugin.sma =====
ERROR [90]: undefined symbol "fmt"

ezhttp_save_data_to_file(request_id, fmt("addons/amxmodx/response_%d.json", request_id))

If I remove this line, plugin compiles and seems to be working ok.
Are the warnings in easy_http.inc normal? Is it ok to ignore them? I'm using amx 1.8.2 .

Last edited by ghostdlr; 11-23-2022 at 13:10.
ghostdlr is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 11-23-2022 , 21:47   Re: I need a library to encode as JSON and HTTP POST, GET
Reply With Quote #16

Quote:
Originally Posted by ghostdlr View Post
===== plugin.sma =====
ERROR [90]: undefined symbol "fmt"

ezhttp_save_data_to_file(request_id, fmt("addons/amxmodx/response_%d.json", request_id))
You can replace it with native formatex(); if you need.

Was fmt(); introduces in 1.9?
Quote:
Originally Posted by string.inc
PHP Code:
/**
 * Formats and returns a string according to the AMX Mod X format rules
 * (see documentation).
 *
 * @note Example: menu_additem(menu, fmt("My first %s", "item")).
 * @note This should only be used for simple inline formatting like in the above example.
 *       Avoid using this function to store strings into variables as an additional
 *       copying step is required.
 * @note The buffer size is defined by MAX_FMT_LENGTH.
 *
 * @param format        Formatting rules.
 * @param ...           Variable number of format parameters.
 *
 * @return              Formatted string
 */
native [MAX_FMT_LENGTH]fmt(const format[], any:...); 
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 11-23-2022 at 21:47.
kww is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-25-2022 , 22:25   Re: I need a library to encode as JSON and HTTP POST, GET
Reply With Quote #17

Quote:
Originally Posted by kww View Post
Was fmt(); introduces in 1.9?
Yes, it was added on February 4th, 2016 which is in the 1.9-dev branch of the code.

Quote:
Originally Posted by kww View Post
You can replace it with native formatex(); if you need.
You can't replace it with formatex() directly, you have to create a buffer variable that you would format into with formatex() and then use that buffer variable instead of fmt(). I assume you probably know that but I figured for clarity of others who might not understand what "replacing" it requires.
__________________

Last edited by fysiks; 11-25-2022 at 22:30.
fysiks is offline
ghostdlr
Senior Member
Join Date: Aug 2010
Old 11-26-2022 , 05:00   Re: I need a library to encode as JSON and HTTP POST, GET
Reply With Quote #18

formatex worked. Thanks.

So eventually I decided on using AmxxEasyHttp and I'm sending all the variables as headers in a post request to my web server.
I don't need sockets or json at all. It works perfectly. Even if I spam the server with messages (like 10 requests at the same time), AmxxEasyHttp is doing them in parallel on multiple threads.

Last edited by ghostdlr; 11-26-2022 at 05:03.
ghostdlr is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 11-26-2022 , 07:26   Re: I need a library to encode as JSON and HTTP POST, GET
Reply With Quote #19

Quote:
Originally Posted by fysiks View Post
Yes, it was added on February 4th, 2016 which is in the 1.9-dev branch of the code.
Are you too angry to answer stupid questions? Thank you

Quote:
Originally Posted by fysiks View Post
You can't replace it with formatex() directly, you have to create a buffer variable that you would format into with formatex() and then use that buffer variable instead of fmt(). I assume you probably know that but I figured for clarity of others who might not understand what "replacing" it requires.
Why are you picking on words? I think they have to use their head and look at docs
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 11-26-2022 at 07:29.
kww is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-26-2022 , 16:48   Re: I need a library to encode as JSON and HTTP POST, GET
Reply With Quote #20

Quote:
Originally Posted by kww View Post
Are you too angry to answer stupid questions? Thank you
Uh . . . what?


Quote:
Originally Posted by kww View Post
Why are you picking on words? I think they have to use their head and look at docs
I'm not "picking on words" (whatever that means), I'm clarifying for people who might not be as familiar with these functions already. It's not a critique of you.
__________________
fysiks 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 13:38.


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