Created
December 5, 2023 10:11
-
-
Save nir9/838254f305696b13e271337a7b65b919 to your computer and use it in GitHub Desktop.
Minimalist C HTTPS Client - Not for production use, only for fun :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#include <openssl/ssl.h> | |
#include <string.h> | |
#include <stdio.h> | |
void main() { | |
int sockfd = socket(AF_INET, SOCK_STREAM, 0); | |
struct sockaddr_in addr = { | |
AF_INET, | |
htons(443), | |
htonl(0x08080808) | |
}; | |
connect(sockfd, &addr, sizeof(addr)); | |
SSL_CTX* ctx = SSL_CTX_new(TLS_method()); | |
SSL* ssl = SSL_new(ctx); | |
SSL_set_fd(ssl, sockfd); | |
SSL_connect(ssl); | |
char* request = "GET /\r\n\r\n"; | |
SSL_write(ssl, request, strlen(request)); | |
char buffer[1024] = {0}; | |
SSL_read(ssl, buffer, 1023); | |
printf("Response:\n%s\n", buffer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment