39 lines
842 B
C
39 lines
842 B
C
#ifndef __HTTP_CLIENT_H
|
|
#define __HTTP_CLIENT_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "socket.h"
|
|
#include <string.h>
|
|
|
|
// HTTP响应缓冲区大小
|
|
#define HTTP_BUFFER_SIZE 2048
|
|
|
|
// HTTP请求结果
|
|
typedef enum {
|
|
HTTP_OK = 0,
|
|
HTTP_ERROR_SOCKET = -1,
|
|
HTTP_ERROR_CONNECTION = -2,
|
|
HTTP_ERROR_SEND = -3,
|
|
HTTP_ERROR_RECEIVE = -4
|
|
} http_result;
|
|
|
|
// HTTP响应结构体
|
|
typedef struct {
|
|
uint8_t buffer[HTTP_BUFFER_SIZE]; // 响应数据缓冲区
|
|
uint16_t length; // 响应数据长度
|
|
} http_response;
|
|
|
|
// 解析URL
|
|
void parse_url(const char* url, char* host, char* path, uint16_t* port);
|
|
|
|
// 使用IP地址的HTTP GET请求
|
|
http_result http_get_ip(const uint8_t* ip, uint16_t port, const char* path, http_response* response);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __HTTP_CLIENT_H */ |