1

从 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高手 谢谢

4

1 回答 1

1

您不能使用https发送原始文本,它需要 SSL 或 TLS。根据您正在使用的平台,您可以使用gnutlsopenssl。并使您的套接字TLS能够向/从服务器发送/接收加密数据。

于 2016-01-15T14:26:49.517 回答