Proxy authentication failed error code is 407. Same code works fine without proxy.
-
The above code works fine if no proxy authentication at server side. It fails as soon as proxy authentication is applied. Please help me to sort out whre i am wrong. Any kind of help appreciated. CInternetSession ises(NULL,1,INTERNET_OPEN_TYPE_PROXY, _T("192.168.9.10:8080"),NULL); CFile* file=new CFile();//There might occur a connection error try { CString url = _T("http://someurl.com/somepath";) DWORD dwFlags = INTERNET_FLAG_TRANSFER_ASCII | INTERNET_FLAG_EXISTING_CONNECT; file = ises.OpenURL(url);//CInternetSession::OpenURL(url) returns a source code in CHttpFile; } catch(CInternetException* e) { //If an error occured, show messagebox with errorcode } //catch(CInternetException *ex) catch(CException *ex) { WCHAR str[500]; DWORD errorCode = GetLastError(); ex->GetErrorMessage(str, GetLastError()); AfxMessageBox(str); } CString result; UINT len=1024; char buf[1024]; source=L""; while(len > 0) { len=file->Read(buf,1024); if(len>0) result.Append(CString(buf),len); } file->Close(); ises.Close(); Thanks and Regards, Amar Mhetre
-
The above code works fine if no proxy authentication at server side. It fails as soon as proxy authentication is applied. Please help me to sort out whre i am wrong. Any kind of help appreciated. CInternetSession ises(NULL,1,INTERNET_OPEN_TYPE_PROXY, _T("192.168.9.10:8080"),NULL); CFile* file=new CFile();//There might occur a connection error try { CString url = _T("http://someurl.com/somepath";) DWORD dwFlags = INTERNET_FLAG_TRANSFER_ASCII | INTERNET_FLAG_EXISTING_CONNECT; file = ises.OpenURL(url);//CInternetSession::OpenURL(url) returns a source code in CHttpFile; } catch(CInternetException* e) { //If an error occured, show messagebox with errorcode } //catch(CInternetException *ex) catch(CException *ex) { WCHAR str[500]; DWORD errorCode = GetLastError(); ex->GetErrorMessage(str, GetLastError()); AfxMessageBox(str); } CString result; UINT len=1024; char buf[1024]; source=L""; while(len > 0) { len=file->Read(buf,1024); if(len>0) result.Append(CString(buf),len); } file->Close(); ises.Close(); Thanks and Regards, Amar Mhetre
try below code to set proxy settings,may be it will help you...
CInternetSession ises; INTERNET\_PROXY\_INFO proxyinfo; proxyinfo.dwAccessType = INTERNET\_OPEN\_TYPE\_PROXY; proxyinfo.lpszProxy = "192.168.9.10:8080"; proxyinfo.lpszProxyBypass = NULL; ises.SetOption(INTERNET\_OPTION\_PROXY,(LPVOID)&proxyinfo,sizeof(INTERNET\_PROXY\_INFO));
-
try below code to set proxy settings,may be it will help you...
CInternetSession ises; INTERNET\_PROXY\_INFO proxyinfo; proxyinfo.dwAccessType = INTERNET\_OPEN\_TYPE\_PROXY; proxyinfo.lpszProxy = "192.168.9.10:8080"; proxyinfo.lpszProxyBypass = NULL; ises.SetOption(INTERNET\_OPTION\_PROXY,(LPVOID)&proxyinfo,sizeof(INTERNET\_PROXY\_INFO));
Thanx for your reply. This will set the proxy, but my problem may be to set the credentials for the proxy ( username and password ). THe way "ises.SetOption()" fails for INTERNET_OPTION_PROXY_USERNAME and INTERNET_OPTION_PROXY_PASSWORD. Is there any other way to set user name and pasword. Thanx once again for ur reply.
-
Thanx for your reply. This will set the proxy, but my problem may be to set the credentials for the proxy ( username and password ). THe way "ises.SetOption()" fails for INTERNET_OPTION_PROXY_USERNAME and INTERNET_OPTION_PROXY_PASSWORD. Is there any other way to set user name and pasword. Thanx once again for ur reply.
Below links might help you.. http://www.informit.com/library/content.aspx?b=Visual_C_PlusPlus&seqNum=107[^] http://graphcomp.com/info/specs/ms/inetr002.htm[^]
-
Below links might help you.. http://www.informit.com/library/content.aspx?b=Visual_C_PlusPlus&seqNum=107[^] http://graphcomp.com/info/specs/ms/inetr002.htm[^]
Thanks for the links. I allready gone through the links and found solution. It should as follows.... HINTERNET hOpenHandle, hConnectHandle, hResourceHandle;WORD dwError, dwErrorCode; hOpenHandle = InternetOpen(NULL,INTERNET_OPEN_TYPE_PROXY, _T("192.168.9.10:8080"), NULL, INTERNET_FLAG_SECURE); // _T("192.168.9.10:8080") is proxy with port number DWORD dwServiceType = AFX_INET_SERVICE_HTTP; CString szServer, szObject; INTERNET_PORT nPort; AfxParseURL (strURL, dwServiceType, szServer, szObject, nPort); // strURL is any URL whose data to retrieve say http://www.google.com hConnectHandle = InternetConnect(hOpenHandle,szServer,INTERNET_INVALID_PORT_NUMBER, _T("test1"), _T("test"), INTERNET_SERVICE_HTTP, 0, 0); // _T("test1"), _T("test") is username and password for proxy at my server hResourceHandle = HttpOpenRequest(hConnectHandle, _T("GET"), szObject, NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); resend: HttpSendRequest(hResourceHandle, NULL, 0, NULL, 0); DWORD dwStatus; DWORD dwStatusSize = sizeof(dwStatus); HttpQueryInfo(hResourceHandle, HTTP_QUERY_FLAG_NUMBER | HTTP_QUERY_STATUS_CODE, &dwStatus, &dwStatusSize, NULL); dwErrorCode = hResourceHandle ? ERROR_SUCCESS : GetLastError(); dwError = InternetErrorDlg(this->GetSafeHwnd(), hResourceHandle, dwErrorCode, FLAGS_ERROR_UI_FILTER_FOR_ERRORS | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA, NULL); if (dwError == ERROR_INTERNET_FORCE_RETRY) goto resend; DWORD dwNumberOfBytesRead; char sz[1024]; int result; do { result = InternetReadFile(hResourceHandle, sz, 1023, &dwNumberOfBytesRead); sz[dwNumberOfBytesRead] = '\0'; int x = strlen(sz); strResult += sz; memset(sz, 0, 1024); } while(result && dwNumberOfBytesRead != 0); return strResult; I was trying/searching this for two days and finally this is done. For others who want proxy authentication, can refer this code. But still there has to be a way by using CInternetSession as it is wrapper to WinInet API's used above. I am happy now that code is working fine now. Thanks once again for your help.