我正在开发一个 C 程序以连接到代理,然后通过代理拉数据/发送数据到网站。然而,在我让“CONNECT”语句起作用后,我对该怎么做感到困惑。
我目前的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#define maxlen 2048
int main(int argc, char *argv[])
{
int mysocket;
int len;
char buffer[2000];
char msg[] = "CONNECT http://example.com:80/ HTPP/1.0\r\n\r\n";
mysocket = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in dest;
memset(&dest, 0, sizeof(dest));
dest.sin_family = AF_INET;
dest.sin_addr.s_addr = inet_addr("101.255.60.162");
dest.sin_port = htons(3128);
connect(mysocket, (struct sockaddr *)&dest, sizeof(struct sockaddr));
send(mysocket, msg, strlen(msg), 0);
len = recv(mysocket, buffer, maxlen, 0);
buffer[len] = '\0';
printf("%s \n", buffer);
close(mysocket);
return 0;
之后我尝试发送另一个命令,但是当我发送第二个命令时,它直接进入站点,而不是通过代理。
提前致谢!!