【首发?】简单的 [Http Get请求&Json解析] 实例

ELDment 二级用户组 2022-11-15 753

.:前言:.

感谢茶糜给我的赞助,要不就整不出科技与狠活力!

本文使用ripext拓展,当然你也可以使用System2拓展cURL拓展

但是不知道cURL拓展是不是年久失修,反正在使用过程中.inc报错,

便转战ripext拓展了

 

.:代码:.

#include <sourcemod>
#include <ripext>
public Plugin myinfo =
{
    name = "Test",
    author = "ELDment",
    description = "Http Get&Json Test",
    version = "1.0.0",
    url = "http://github.com/ELDment"
};
public void OnPluginStart()
{
    RegConsoleCmd("sm_ht", OnCommand, "Test");
}
public Action OnCommand(int client, int args)
{
    PrintToChat(client, "Get");
    PrintToServer("Get");
    HTTPRequest request = new HTTPRequest("http://43.143.135.75:18888/index.php?method=xPaw&host=202.189.7.59&port=27100&type=info");
    request.Get(OnTodoReceived, client);
}
void OnTodoReceived(HTTPResponse response, int client)
{
    if (response.Status != HTTPStatus_OK) {
        PrintToServer("Oops, something went wrong!");
        return;
    }
    JSONObject todo = view_as<JSONObject>(response.Data);
    char GetMap[256];
    todo.GetString("Map", GetMap, sizeof(GetMap));
    PrintToChat(client, "The current map is '%s'", GetMap);
    PrintToServer("The current map is '%s'", GetMap);
}

 

.:输出:.

(↑ Client端 ↑)[有两个输出是因为我分别对sm_ht以及!ht进行了测试]

(↑ Server端 ↑)[有两个输出是因为我分别对sm_ht以及!ht进行了测试]

(↑ Web端 ↑)

 


CSGO插件分享-申明 1、本网站名称:CSGO插件分享-中文站  网址:https://bbs.csgocn.net
2、本站的宗旨在于为CSGO玩家提供一个插件分享的中文资源平台,多数插件来源于SourceMod论坛,并配以中文介绍和安装教程。
3、欢迎有能力的朋友共享有趣的CSGO插件资源。
4、本站资源大多为百度网盘,如发现链接失效,可以点: 这里进行反馈,我们会第一时间更新。
最新回复 (2)
返回