asxe
asxe

# 获取源文件

点击 libeasyhttp 下载

# 使用方法

请求所返回类型均为 HTTP_RESPONSE 结构。其定义如下 <br>

typedef struct HTTP_RESPONSE {
long status; //请求状态码
char *text; //文本
double total_time; //请求耗时
} HTTP_RESPONSE;
  1. 发送 get 请求,原型为:<br>HTTP_RESPONSE get (const char *url, HEADERS *headers);
#include "libeasyhttp/easy-http.h"

int main(void) {
    HEADERS *headerList = NULL;
    
    headerList = addHeader(headerList, "Content-Type", "text/html; charset=utf-8");
    headerList = addHeader(headerList, "User-Agent", "ASXE");
    
    HTTP_RESPONSE httpResponse = get("https://www.asxe.vip/", headerList);
    printf("%s", httpResponse.text);
    printf("%ld", httpResponse.status);
    printf("%f", httpResponse.total_time);
    return 0;
}
  1. 发送 post 请求,原型为 <br>HTTP_RESPONSE post (const char *url, HEADERS *headers, POST_DATA *postData);
#include "libeasyhttp/easy-http.h"

int main(void) {
    HEADERS *headerList = NULL;
    POST_DATA *postData = NULL;
    
    headerList = addHeader(headerList, "User-Agent", "ASXE");
    
    postData = addData(postData, "q", "测试");
    
    HTTP_RESPONSE httpResponse = post("http://127.0.0.1:1314/search/", headerList, postData);
    printf("%s", httpResponse.text);
    printf("%ld", httpResponse.status);
    printf("%f", httpResponse.total_time);
    return 0;
}