winnet
#include <iostream>
#include <exception>
#include <windows.h>
#include <wininet.h>
#include <fstream>
#include <conio.h>
using namespace std;
#pragma comment(lib,"wininet.lib")
int main(int argc, char* argv[])
{
HINTERNET hOpenHandle, hConnectHandle, hResourceHandle;
DWORD dwError, dwStatus;
DWORD dwStatusSize = sizeof(dwStatus);
hOpenHandle = InternetOpen("TestAgent",INTERNET_OPEN_TYPE_PRECONFIG,NULL, NULL, 0);
hConnectHandle = InternetConnect(hOpenHandle,"https://www.google.com/accounts/",INTERNET_DEFAULT_HTTPS_PORT,"user","pass",INTERNET_SERVICE_HTTP,0,0);
hResourceHandle = HttpOpenRequest(hConnectHandle, "POST","ServiceLoginAuth?service=mail",NULL, NULL,NULL,INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_CACHE_WRITE,0);
BOOL fResult = HttpSendRequest(hResourceHandle, NULL, 0, NULL, 0);
if ( fResult == false )
{
cout<<"HttpSendRequest failed!"<<endl;
cout<<"GetLastError(): "<<::GetLastError()<<endl;
}
HttpQueryInfo(hResourceHandle, HTTP_QUERY_FLAG_NUMBER |
HTTP_QUERY_STATUS_CODE, &dwStatus,
&dwStatusSize, NULL);
switch (dwStatus)
{
case HTTP_STATUS_PROXY_AUTH_REQ: // Proxy Authentication
case HTTP_STATUS_DENIED: // Server Authentication Required.
cout<< "auth failed!"<<endl;
break;
case HTTP_STATUS_OK:
cout<< "auth pass!"<<endl;
break;
default:
cout<< "what happens here?"<<endl;
break;
}
return 0;
}