Linux sockets + http get request = no data

Started by
15 comments, last by hplus0603 4 years, 8 months ago

Yes, gethostbyname() should take the string "www.google.com"

Separately, the Host: header does not include the protocol, but it (can) include the port number. Thus, the Host: header should be "www.google.com" or "www.google.com:80" not "http://www.google.com"

I wrote a small library to do exactly what you want to do, and the last version update was 11 years ago. Time flies ... You may want to read the source code: http://www.enchantedage.com/http-get

 

enum Bool { True, False, FileNotFound };
Advertisement

I just read your code and compared it to mine: after.changing

                sockfd = socket(AF_INET, SOCK_STREAM, 0); to

                sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 

Web page is being downloaded.

Hopefully i won't run into any additional problems, thanks and cheers

i wonder if i could somehow estabilish https connection here. the thing is i dont know the steps involved say i have generated client ssl certificate - do i use that and pass it in get request and if yes how? its a bit offtopic, after i figured that i need https connection i had to use java wrapper for that.... (still prefer cpp way)

OpenSSL has an API for that. But i have no detail knowledge ...

Use a C++ HTTPS library, e.g. this one. There is a ca-bundle.crt file with the root certificates that you should trust. I recommend creating that file yourself automatically based on the trusted certificates on the user's computer, I'm not sure where to get those in linux though.

HTTPS is significantly harder than HTTP, because you talk the HTTP protocol over TLS, and the available TLS libraries are all kind-of hard to work with. Especially OpenSSL is known to have an API mainly intended to support the OpenSSH project, and only accidentally also somewhat usable for establishing TLS connections ... Then again, the "chain of trust" security model of TLS is, in itself, not super simple, and thus requires some necessary complexity, including an up to date root certificate store, and mechanism to evolve that store over time.

There's GnuTLS, fizz, mbed TLS, and a few other contenders you might want to look at.

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement