-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
52 lines (44 loc) · 1.43 KB
/
test.c
File metadata and controls
52 lines (44 loc) · 1.43 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
#include <stdio.h>
#include "http_client.h"
int main() {
printf("HTTP Client Library Test\n");
printf("========================\n\n");
// Create HTTP client
http_client_t* client = http_client_create("MyApp/1.0");
if (!client) {
printf("Failed to create HTTP client\n");
return 1;
}
// Test GET request
printf("Testing GET request...\n");
http_response_t* response = http_get(client, "https://httpbin.org/get");
if (response) {
printf("Status Code: %d\n", response->status_code);
printf("Body Length: %zu\n", response->body_length);
if (response->body) {
printf("Body: %s\n", response->body);
}
http_response_destroy(response);
} else {
printf("GET request failed\n");
}
printf("\n");
// Test POST request
printf("Testing POST request...\n");
const char* post_data = "{\"test\": \"data\"}";
response = http_post(client, "https://httpbin.org/post", post_data, "application/json");
if (response) {
printf("Status Code: %d\n", response->status_code);
printf("Body Length: %zu\n", response->body_length);
if (response->body) {
printf("Body: %s\n", response->body);
}
http_response_destroy(response);
} else {
printf("POST request failed\n");
}
// Cleanup
http_client_destroy(client);
printf("\nTest completed.\n");
return 0;
}