Jump to content
  • Advertisement
_WeirdCat_

Linux sockets + http get request = no data

Recommended Posts

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

 

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!