小编Hba*_*all的帖子

C++套接字连接中的OpenSSL(HTTPS客户端)

我写了一个脚本,可以创建与HTTP服务器的连接,并在控制台中显示网站的内容.很容易.

但我想连接到https服务器并执行相同的过程.我在谷歌搜索,没有找到我搜索的内容.

请帮帮我,给我一个教程,我可以使用openssl库.

我在openssl库上尝试过自己,但是库非常复杂且难以理解.

这是我的http客户端代码:

#include <iostream>
#include <ctype.h>
#include <cstring>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sstream>
#include <fstream>
#include <string>
#include <arpa/inet.h>
#include <openssl/ssl.h>

using namespace std;

int sock;
struct sockaddr_in client;
int PORT = 80;

int main(int argc, char const *argv[])
{
    bzero(&client, sizeof(client));
    client.sin_family = AF_INET;
    client.sin_port = htons( PORT );
    client.sin_addr.s_addr = inet_addr("172.16.0.6");

    sock = socket(AF_INET, SOCK_STREAM, 0);

    if (sock < 0) {
        cout << "Error creating socket." …
Run Code Online (Sandbox Code Playgroud)

c++ sockets https openssl

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

https ×1

openssl ×1

sockets ×1