Home > Software engineering >  Turn the MFC, how to verify the HTTP SOCK5 validity of proxy IP, my code is invalid
Turn the MFC, how to verify the HTTP SOCK5 validity of proxy IP, my code is invalid

Time:09-28

Suppose now have HTTP proxy IP: 192.168.1.1 port is 80
SOCK5 proxy IP: 192.168.1.2 instead port is 80, but there are SOCK5 account password authentication account: user password: passd

How can you tell me the next in the MFC to the two IP proxy authentication is valid? Attach my own part of the code, moved from the Internet and tested under
Proxy IP address port password whatever written for don't know where the problem is effective for help!!

 
Cstrings content;
Bool TestProxyData (LPCTSTR Proxy, LPCTSTR ProxyPassd)//Proxy IP detection function
{
Cstrings data;
DWORD dwStatusCode;
CInternetSession session (" HttpClient ");
CHttpFile * pfile=NULL;
INTERNET_PROXY_INFO proxyinfo;
Proxyinfo. DwAccessType=INTERNET_OPEN_TYPE_PROXY;
Proxyinfo. LpszProxy=Proxy;
Proxyinfo. LpszProxyBypass=ProxyPassd;
The session. SetOption (INTERNET_OPTION_PROXY, (LPVOID) & amp; Proxyinfo, sizeof (INTERNET_PROXY_INFO));
The session. SetOption (INTERNET_OPTION_CONNECT_TIMEOUT, 2000);//2 seconds, the connection timeout
The session. SetOption (INTERNET_OPTION_SEND_TIMEOUT, 1000);//1 seconds to send timeout
The session. SetOption (INTERNET_OPTION_RECEIVE_TIMEOUT, 7000);//7 seconds to receive timeout
The session. SetOption (INTERNET_OPTION_DATA_SEND_TIMEOUT, 1000);//1 seconds to send timeout
The session. SetOption (INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, 7000);//7 seconds to receive timeout
The session. SetOption (INTERNET_OPTION_CONNECT_RETRIES, 1);//1 retries
Try
{
Pfile=(CHttpFile *) session. OpenURL (" http://ip.dnsexit.com/", 1, INTERNET_FLAG_TRANSFER_ASCII | INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE);
}
The catch (CInternetException * e)
{
Pfile=NULL;
E - & gt; The Delete ();
The session. The Close ();
return false;
}
Pfile - & gt; QueryInfoStatusCode (dwStatusCode);
If (dwStatusCode==HTTP_STATUS_OK)
{
While (pfile - & gt; ReadString (data))
{
Content +=data;
}
Pfile - & gt; Close ();
The session. The Close ();
return true;
}
The else
{
return false;
}
}

Typedef struct tagProxyIP {
Int num.//serial number
Cstrings ProxyIP;//proxy IP address
Cstrings IPtype;//IP type
Int nPot;//proxy port
Cstrings IPUser;//proxy IP account
Cstrings IPpwd;//proxy IP password
Cstrings ISnormal.//is valid
} stcProxyIP;
//structure used in the proxy IP list

Vector G_vecIP;//use a container to save agent IP

Cstrings buf, buf1 and buf2="";
for (int i=0; I{
Buf. The Format (" % d ", g_vecIP [I] nPot);
If (g_vecIP [I] IPUser=="")
{
Buf1=g_vecIP [I] ProxyIP + ":" + buf;
} else if (g_vecIP [I] IPUser!="")
{
Buf1=g_vecIP [I] ProxyIP + ":" + buf;
Buf2=g_vecIP [I] IPUser + ":" + g_vecIP [I] IPpwd;
}
If (TestProxyData (buf1 and buf2))
{
G_vecIP [I] ISnormal="effective";
} the else
{
G_vecIP [I] ISnormal="invalid";
}

}

CodePudding user response:

CInternetSession: : CInternetSession construct is called InternetOpen,
So try fill out the agent in the constructor parameters

CInternetSession session (" HttpClient ", 1, INTERNET_OPEN_TYPE_PROXY, XXXXXXXXX);
  • Related