简体   繁体   中英

How does the http get request differ from the https request in c?

There was an earlier implementation of get and post http request from C-language POS system to the server. However for reasons of security the server only accepts https on port 443.

The implementation has failed to work on port 443 indication http errors 400/362.

Here is sample code,

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 no expert at C Thank you

You can't send raw text with https it requires SSL or TLS. Depending on the platform you are working on you could use gnutls or openssl . And make your socket TLS capable to be able to send/recieve encrypted data to/from the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM