-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_client.h
More file actions
65 lines (54 loc) · 1.63 KB
/
http_client.h
File metadata and controls
65 lines (54 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef HTTP_CLIENT_H
#define HTTP_CLIENT_H
#include <windows.h>
#include <winhttp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma comment(lib, "winhttp.lib")
// HTTP Methods
typedef enum {
HTTP_GET,
HTTP_POST,
HTTP_PUT,
HTTP_DELETE,
HTTP_PATCH
} http_method_t;
// HTTP Response structure
typedef struct {
int status_code;
char* headers;
char* body;
size_t body_length;
size_t headers_length;
} http_response_t;
// HTTP Client structure
typedef struct {
HINTERNET session;
HINTERNET connection;
wchar_t* user_agent;
int timeout_ms;
} http_client_t;
// HTTP Request structure
typedef struct {
http_method_t method;
const char* url;
char* headers;
const char* body;
size_t body_length;
} http_request_t;
// Function declarations
http_client_t* http_client_create(const char* user_agent);
void http_client_destroy(http_client_t* client);
void http_client_set_timeout(http_client_t* client, int timeout_ms);
http_response_t* http_request(http_client_t* client, http_request_t* request);
http_response_t* http_get(http_client_t* client, const char* url);
http_response_t* http_post(http_client_t* client, const char* url, const char* data, const char* content_type);
http_response_t* http_put(http_client_t* client, const char* url, const char* data, const char* content_type);
http_response_t* http_delete(http_client_t* client, const char* url);
void http_response_destroy(http_response_t* response);
// Utility functions
char* http_url_encode(const char* str);
wchar_t* char_to_wchar(const char* str);
char* wchar_to_char(const wchar_t* wstr);
#endif // HTTP_CLIENT_H