Hi, i was wondering if someone could show me how to log into a website using c++ .net? I want to login to say megaupload.com for example, now i have to code in c++ but how could i do it in managed c++? A link or something would be great, i see many examples of this in c# but not in c++ =/. Thanks
#include <winsock2.h>
#include <windows.h>
#include <string.h>
#include <stdio.h>
#pragma comment(lib,"ws2_32.lib")
#define HOST "www.megaupload.com"
#define PORT 80
#define LEN 534 // Points to contenth length in http_req[]
int hconnect(char* host,int port);
int s=0;
char http_req[]=
"POST /?c=login HTTP/1.1\r\n"
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */* \r\n"
"Referer: http://megaupload.com/?c=login\r\n"
"Accept-Language: en-US\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"UA-CPU: x86\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)\r\n"
"Host: megaupload.com\r\n"
"Content-Length: 00\r\n" // LEN points here!!!
"Connection: Keep-Alive\r\n"
"Cache-Control: no-cache\r\n\r\n";
char http_line_req[]="login=1&redir=1&username=usernamehere&password=passhere\r\n\r\n"; // fill in here
char conn[1024];
int nLen=0;
char szLen[2];
void main()
{
nLen=strlen(http_line_req);
itoa(nLen,szLen,10);
memcpy(http_req+LEN,szLen,2);
s=hconnect(HOST,PORT);
send(s,http_req,strlen(http_req),NULL);
send(s,http_line_req,nLen,NULL);
recv(s,conn,1024,NULL);
//TODO: continue recv'ing, that 1KB buffer is not enough to recv all the data :)
}
int hconnect(char* host,int port)
{
WSAData wsa;
WSAStartup(MAKEWORD(1,1),&wsa);
struct sockaddr_in sai;
struct hostent *hp;
memset(&sai,0,sizeof(struct sockaddr_in));
hp=gethostbyname(host);
sai.sin_family=AF_INET;
sai.sin_addr=*((struct in_addr *)hp->h_addr);
sai.sin_port=htons(port);
SOCKET s;
s=socket(AF_INET,SOCK_STREAM,0);
connect(s,(struct sockaddr*)&sai,sizeof(sockaddr));
return s;
}