i'm trying use getaddrinfo giving http(s) prefix , doesn't host correctly. how can fix problem. want https://www.google.com gai_strerror()
returns "no such host known", works okay www.google.com on port 80.
this part of code i'm using getaddrinfo() part:
// request pose download webpage char *send_buf="get / \r\n"; // tried 3 different urls apparently changing value in // value in variable in code, works 'www.google.com' const char *url="https://www.google.com"; const char *url="http://www.google.com"; const char *url="www.google.com"; if( ( status=getaddrinfo(url, port, &hints, &res) )!=0 ) { printf("%s\n", gai_strerror(status)); exit(1); }
i'm trying download webpage using winsock2 , when use www.google.com, gives me 302 moved message , i'd download actual webpage without using external libraries.
you have give either ip address or hostname of desired host. if give hostname converted respective ip address(es). hostname should in form only: "www.example.domain_name"
. not include "http://"
or "https://"
. property of url includes hostname, not part of hostname itself.
to download html https://www.google.com
, have lookup ip www.google.com
, connect ip on port 443 (the default https port), negotiate ssl/tls encryption session, , send http get
request /
document.
it not wise implement ssl/tls encryption hand. use library, such openssl, or microsoft's own cryptoapi, on top of existing socket code. alternatively, don't use socket apis directly @ all, use http/s library, such microsoft's own wininet/winhttp api, or library libcurl, handle of details you.
Comments
Post a Comment