主要验证http的post方法,此处测试了2个url,有tcp直连方式也有tls加密方式,均是正常的,httpbin.org这个网站就是用于测试http协议的利器。
#include <stdio.h>
#include <unistd.h>
#include <httpclient.h>
extern const char *ca_get();
#define URL1 "http://httpbin.org/post" // tcp
#define URL2 "https://httpbin.org/post" // tls
static int _http_cb(void *e)
{
http_event_t *event = e;
printf("%s", (char*)event->data);
return 0;
}
void http_post_test(void)
{
printf("\n---------------------- http_post_test start ----------------------\n");
http_client_init(ca_get());
printf("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n");
http_client_post(URL1, "this is a post test ...", _http_cb);
printf("\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
printf("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n");
http_client_post(URL2, "this is a post test ...", _http_cb);
printf("\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
printf("\n---------------------- http_post_test end ----------------------\n");
}
---------------------- http_post_test start ----------------------
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{
"args": {},
"data": "this is a post test ...\r\n\r",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Content-Length": "26",
"Content-Type": "text/plain",
"Host": "httpbin.org",
"User-Agent": "http-client-by-jiejie",
"X-Amzn-Trace-Id": "Root=1-5ec2a299-03a9fd77fdaf6ecf2aa5fdc2"
},
"json": null,
"origin": "210.6.9.16",
"url": "http://httpbin.org/post"
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{
"args": {},
"data": "this is a post test ...\r\n\r",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Content-Length": "26",
"Content-Type": "text/plain",
"Host": "httpbin.org",
"User-Agent": "http-client-by-jiejie",
"X-Amzn-Trace-Id": "Root=1-5ec2a29f-b46e156061af6ce0873b3ff0"
},
"json": null,
"origin": "210.6.9.16",
"url": "https://httpbin.org/post"
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
---------------------- http_post_test end ----------------------
上一篇:get方法测试
下一篇: 重定向测试