Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _WINSOCK_DEPRECATED_NO_WARNINGS
- #include <string.h>
- #include <winsock2.h>
- #include <windows.h>
- #include <iostream>
- #include <vector>
- #include <locale>
- #include <sstream>
- #include "stdafx.h"
- #include <string>
- #include "curl/curl.h";
- using namespace std;
- #pragma comment(lib,"ws2_32.lib")
- string HttpGet(string url,string port);
- int main(void) {
- string x = HttpGet("127.0.0.1" , "80");
- cout << x;
- cout << "\n\nPress ANY key to close.\n\n";
- cin.ignore(); cin.get();
- return 0;
- }
- string HttpGet(string url,string port) {
- char buffer[10000];
- int i = 0;
- string Response;
- WSADATA wsaData;
- SOCKET Socket;
- SOCKADDR_IN SockAddr;
- int lineCount = 0;
- int rowCount = 0;
- struct hostent *host;
- string header;
- string newl = "\n";
- //get_http = "GET /index.php HTTP/1.1\r\n " + newl + "Host: " + url + "\r\nConnection: close\r\n\r\n";
- header = "GET /index.php HTTP/1.1\r\n";
- header += "Host: " + url + ":" + port + "\r\n"; // we need to specify the port
- header += "Connection: close\r\n\r\n";
- if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
- Response = "Failed.";
- }
- Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- host = gethostbyname(url.c_str());
- SockAddr.sin_port = htons(80);
- SockAddr.sin_family = AF_INET;
- SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
- if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0) {
- Response = "Failed.";
- }
- send(Socket, header.c_str(), strlen(header.c_str()), 0);
- int nDataLength;
- while ((nDataLength = recv(Socket, buffer, 10000, 0)) > 0) {
- int i = 0;
- while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r') {
- Response += buffer[i];
- i += 1;
- }
- }
- return Response;
- closesocket(Socket);
- WSACleanup();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement