发送简单的HTTP GET请求,返回响应体字符串。
const char* HttpGet(int64_t instance, const char* url)
| 参数名 | 类型 | 说明 |
|---|
| instance | int64_t | OLAPlug对象的指针 |
| url | string | 完整URL |
const char* response = HttpGet(instance, "https://api.example.com/data");
if (response != NULL) {
printf("响应内容:%s\n", response);
FreeStringPtr(instance, response);
} else {
printf("请求失败\n");
}
const char* json = HttpGet(instance, "https://api.example.com/users/123");
if (json != NULL) {
FreeStringPtr(instance, json);
}
const char* html = HttpGet(instance, "https://www.example.com");
if (html != NULL) {
printf("网页内容:%s\n", html);
FreeStringPtr(instance, html);
}
| 返回值类型 | 说明 |
|---|
| string | 响应体字符串指针,失败返回NULL,需调用FreeStringPtr释放 |
- 返回的字符串需要调用
FreeStringPtr 释放内存 - 适合简单的GET请求
- 如需自定义请求头或Cookie,请使用
HttpRequestEx - 支持HTTP和HTTPS协议