Home > Software engineering >  OpenUrl problem again, please grant instruction oh old driver, the fast mad...
OpenUrl problem again, please grant instruction oh old driver, the fast mad...

Time:09-24

A very simple code


 CInternetSession is; 
CHttpFile * file=(CHttpFile *) is the OpenURL (url);


IE set up agent, and can be normal access to the Internet web page, the same url that can be accessed in IE and Chrome, but inside the code will not be able to access, return 12029 (unable to establish connection with the server), tried all sorts of online way to not make,

Code inside access Intranet web page is no problem, but just can not access the web page,

don't know how to set up a proxy to just go? After set up agency in IE, the code will also need to set?

The odd thing is that the code can be run for a period of time, but how also not line,

CodePudding user response:

 
Cstrings GeHttptFile (const char * url, char * Proxy, char * UseName, char * Password)
{
Cstrings szContent;
StrUsername char strProxyList [MAX_PATH], [64], strPassword [64].
//in this case "proxya" is the proxy server name, "8080" is its port
Strcpy (strProxyList, Proxy);
Strcpy (strUsername, UseName);
Strcpy (strPassword, Password);
DWORD dwServiceType=AFX_INET_SERVICE_HTTP;
Cstrings szServer szObject;
INTERNET_PORT nPort.
AfxParseURL (url, dwServiceType szServer szObject, nPort);
CInternetSession mysession;
CHttpConnection * pConnection;
CHttpFile * pHttpFile;
PConnection=mysession. GetHttpConnection (szServer.
INTERNET_FLAG_KEEP_CONNECTION,
INTERNET_INVALID_PORT_NUMBER,
NULL, NULL);
PHttpFile=pConnection - & gt; OpenRequest (" POST ", szObject,
NULL, 0, NULL, NULL,
INTERNET_FLAG_KEEP_CONNECTION);
//here for proxy
INTERNET_PROXY_INFO proxyinfo;
Proxyinfo. DwAccessType=INTERNET_OPEN_TYPE_PROXY;
Proxyinfo. LpszProxy=strProxyList;
Proxyinfo. LpszProxyBypass=NULL;
Mysession. SetOption (INTERNET_OPTION_PROXY, (LPVOID) & amp; Proxyinfo, sizeof (INTERNET_PROXY_INFO));
PHttpFile - & gt; SetOption (INTERNET_OPTION_PROXY_USERNAME strUsername, strlen (strUsername) + 1);
PHttpFile - & gt; SetOption (INTERNET_OPTION_PROXY_PASSWORD, strPassword, strlen (strPassword) + 1);

PHttpFile - & gt; The SendRequest (NULL);
DWORD nFileSize=pHttpFile - & gt; GetLength ();
LPSTR rbuf=szContent. GetBuffer (nFileSize);
UINT uBytesRead=pHttpFile - & gt; Read (rbuf nFileSize);
SzContent. ReleaseBuffer ();
PHttpFile - & gt; Close ();
The delete pHttpFile;
PConnection - & gt; Close ();
The delete pConnection;
Mysession. Close ();
Return szContent;
}

CodePudding user response:

Only help # 1 with format:
 cstrings GeHttptFile (const char * url, char * Proxy, char * UseName, char * Password) {
Cstrings szContent;
StrUsername char strProxyList [MAX_PATH], [64], strPassword [64].
//in this case "proxya" is the proxy server name, "8080" is its port
Strcpy (strProxyList, Proxy);
Strcpy (strUsername, UseName);
Strcpy (strPassword, Password);
DWORD dwServiceType=AFX_INET_SERVICE_HTTP;
Cstrings szServer szObject;
INTERNET_PORT nPort.
AfxParseURL (url, dwServiceType szServer szObject, nPort);
CInternetSession mysession;
CHttpConnection * pConnection;
CHttpFile * pHttpFile;
PConnection=mysession. GetHttpConnection (szServer.
INTERNET_FLAG_KEEP_CONNECTION,
INTERNET_INVALID_PORT_NUMBER,
NULL, NULL);
PHttpFile=pConnection - & gt; OpenRequest (" POST ", szObject,
NULL, 0, NULL, NULL,
INTERNET_FLAG_KEEP_CONNECTION);
//here for proxy
INTERNET_PROXY_INFO proxyinfo;
Proxyinfo. DwAccessType=INTERNET_OPEN_TYPE_PROXY;
Proxyinfo. LpszProxy=strProxyList;
Proxyinfo. LpszProxyBypass=NULL;
Mysession. SetOption (INTERNET_OPTION_PROXY, (LPVOID) & amp; Proxyinfo, sizeof (INTERNET_PROXY_INFO));
PHttpFile - & gt; SetOption (INTERNET_OPTION_PROXY_USERNAME strUsername, strlen (strUsername) + 1);
PHttpFile - & gt; SetOption (INTERNET_OPTION_PROXY_PASSWORD, strPassword, strlen (strPassword) + 1);

PHttpFile - & gt; The SendRequest (NULL);
DWORD nFileSize=pHttpFile - & gt; GetLength ();
LPSTR rbuf=szContent. GetBuffer (nFileSize);
UINT uBytesRead=pHttpFile - & gt; Read (rbuf nFileSize);
SzContent. ReleaseBuffer ();
PHttpFile - & gt; Close ();
The delete pHttpFile;
PConnection - & gt; Close ();
The delete pConnection;
Mysession. Close ();
Return szContent;
}

  • Related