Skip to content

Instantly share code, notes, and snippets.

@dattp
Created November 19, 2016 04:49
Show Gist options
  • Save dattp/4d8a47a0bda2319a257511d8ef493654 to your computer and use it in GitHub Desktop.
Save dattp/4d8a47a0bda2319a257511d8ef493654 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include <WinSock2.h>
#include <WS2tcpip.h>
int main(int argc, char* argv[])
{
WSADATA data;
SOCKET s;
SOCKADDR_IN sa;
int port = 80;
int ec = WSAStartup(MAKEWORD(2, 2), &data);
WSAStartup(MAKEWORD(2, 2), &data);
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
sa.sin_addr.s_addr = inet_addr("222.255.27.51");
//222.255.27.51
connect(s, (SOCKADDR*)&sa, sizeof(sa));
char *buf = "GET / HTTP/1.1\nHost: 127.0.0.1:8888\nConnection: keep-alive\nCache-Control: max-age=0\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\nUpgrade-Insecure-Requests: 1\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/56.3.138 Chrome/50.3.2661.138 Safari/537.36\nAccept-Encoding: gzip, deflate, sdch\nAccept-Language: vi-VN,vi;q=0.8,fr-FR;q=0.6,fr;q=0.4,en-US;q=0.2,en;q=0.2\n\n";
char buffer[1024];
send(s, buf, strlen(buf), 0);
while (true)
{
memset(buffer, 0, sizeof(buffer));
recv(s, buffer, sizeof(buffer), 0);
printf("%s", buffer);
}
system("pause");
closesocket(s);
WSACleanup();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment