从 C 语言 POS 系统到服务器的 get 和 post http 请求有一个较早的实现。但是出于安全原因,服务器仅在端口 443 上接受 https。
该实现未能在端口 443 上工作,指示 http 错误 400/362。
这是示例代码,
char *build_get_query(char *host, char *page)
{
char *query;
char *getpage = page;
char *tpl = "GET /%s HTTP/1.0\r\nHost: %s\r\nUser-Agent: %s\r\n\r\n";
/*if(getpage[0] == '/'){
getpage = getpage + 1;
fprintf(stderr,"Removing leading \"/\", converting %s to %s\n", page, getpage);
} */
// -5 is to consider the %s %s %s in tpl and the ending \0
query = (char *)malloc(strlen(host)+strlen(getpage)+strlen(USERAGENT)+strlen(tpl)-5);
sprintf(query, tpl, getpage, host, USERAGENT);
return query;
}
PS没有C高手 谢谢