acl/lib_acl_cpp/samples/http_test/main.cpp
2023-12-12 11:52:51 +08:00

52 lines
1.4 KiB
C++

#include <list>
#include "acl_cpp/lib_acl.hpp"
using namespace acl;
int main(void)
{
const char* url = "https://127.0.0.1:9001";
acl::http_url parser;
if (!parser.parse(url)) {
printf("invalid url\n");
return 1;
}
printf("domain=%s, port=%d, url=%s\r\n", parser.get_domain(), parser.get_port(), parser.get_url_path());
return 0;
const char* data = "U_TRS1=000000f6.66721803.4fd1681c.8c48b73a; path=/; expires=Mon, 06-Jun-22 02:49:00 GMT; domain=.sina.com.cn";
HttpCookie* cookie = new HttpCookie();
printf("Set-Cookie: %s\r\n", data);
if (cookie->setCookie(data) == false)
{
printf("parse cookie(%s) error\r\n", data);
cookie->destroy();
return -1;
}
printf("cookie name: %s\r\n", cookie->getName());
printf("cookie value: %s\r\n", cookie->getValue());
printf("domain: %s\r\n", cookie->getDomain());
printf("path: %s\r\n", cookie->getPath());
printf("max-age: %d\r\n", cookie->getMaxAge());
const std::list<HTTP_PARAM*>& params = cookie->getParams();
std::list<HTTP_PARAM*>::const_iterator cit = params.begin();
for (; cit != params.end(); ++cit)
printf(">>%s=%s\r\n", (*cit)->name, (*cit)->value);
cookie->destroy();
const char* s = "encrypted/json";
acl::http_ctype hc;
if (hc.parse(s)) {
const char* ctype = hc.get_ctype();
const char* stype = hc.get_stype();
printf("ctype=%s, stype=%s\r\n", ctype, stype);
}
return 0;
}