如何获取一个https网页的源码。
char* req = "GET /xxx/xxx/xxx.json?access_token=2.00oHVeDCKcJ_ND03ded06bcd0iD74q&uid=1644882984 HTTP/1.1\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)\r\n"
"Host:xxx.xxxx.com\r\n\r\n";
system::error_code ec = asio::error::host_not_found;
sock.send(asio::buffer(req ,strlen(req)),0,ec );
代码在http请求下可以正常通过但是访问https的网页我该如何操作呢,大家帮我当白痴,集思广益了,能说多少说多少。
[解决办法]
下个openssl,然后创建ssl的socket。 http://www.openssl.org/docs/ssl/ssl.html
再发http请求即可。
[解决办法]
因为服务器是HTTPS,所以你的application需要服务器的证书,用1楼提供的openssl库即可。
[解决办法]
http://www.informit.com/articles/article.aspx?p=22078&seqNum=3
Writing an SSL client that connects to a secure server is very similar, changing only a few lines of the client code. The server is easier to build first, because you can test it with standard browsers. On the other hand, you have to use a working SSL server (typically custom-built) to verify client functionality. Some parts appear to be identical to the server's equivalent, but note the single difference (in bold).
SSL_METHOD *method;
SSL_CTX *ctx;
OpenSSL_add_all_algorithms(); /* load & register cryptos */
SSL_load_error_strings(); /* load all error messages */
method = SSLv2_client_method(); /* create client instance */
ctx = SSL_CTX_new(method); /* create context */
The only difference is the call to make a client instance using SSLv2_client_method(). After setting up the SSL library, you need to create the socket. Again, the client socket code is essentially a standard TCP socket that finds and connects to a server.
/*---Standard TCP Client---*/
int sd;
struct hostent *host;
struct sockaddr_in addr;
host = gethostbyname(hostname); /* convert hostname ? IP addr */
sd = socket(PF_INET, SOCK_STREAM, 0); /* create TCP socket */
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port); /* set the desired port */
addr.sin_addr.s_addr = *(long*)(host->h_addr); /* and address */
connect(sd, (struct sockaddr*)&addr, sizeof(addr));/* connect */
At this point, the client has succeeded in connecting to the TCP side of the server. Like the server, it must perform the SSL handshaking to complete the transition to a secure channel. The client's handshaking code changes only the last line of the server's code. The client uses the counterpart to SSL_accept(), called SSL_connect().