美文网首页
MT4测试WebRequest的方法

MT4测试WebRequest的方法

作者: AI_Finance | 来源:发表于2025-03-06 08:45 被阅读0次

void OnStart()
{
    string url = "http://127.0.0.1:8000/api/ainance/mt/receive_order";  // 修复 URL 中的冒号
    string jsonData = "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}";
    
    // 为 postData 分配足够的空间
    char postData[1024];
    StringToCharArray(jsonData, postData, 0, StringLen(jsonData), CP_UTF8);

    string headers = "Content-Type: application/json";
    char result[1024];  // 为 result 分配足够的空间
    string resultHeaders;
    string cookie = "";
    int timeout = 10000;

    // 发送请求
    int responseCode = WebRequest("POST", url, headers, cookie, timeout, postData, StringLen(jsonData), result, resultHeaders);

    if (responseCode == 200)
    {
        string response = CharArrayToString(result);
        Print("请求成功,服务器返回:", response);
    }
    else
    {
        int errorCode = GetLastError();
        PrintFormat("请求失败!响应代码:%d,错误代码:%d", responseCode, errorCode);
    }
}

相关文章

网友评论

      本文标题:MT4测试WebRequest的方法

      本文链接:https://www.haomeiwen.com/subject/wrtkmjtx.html