Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
A

amar_mhetre

@amar_mhetre
About
Posts
3
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Proxy authentication failed error code is 407. Same code works fine without proxy.
    A amar_mhetre

    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.

    C / C++ / MFC help com sysadmin security

  • Proxy authentication failed error code is 407. Same code works fine without proxy.
    A amar_mhetre

    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.

    C / C++ / MFC help com sysadmin security

  • Proxy authentication failed error code is 407. Same code works fine without proxy.
    A 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

    C / C++ / MFC help com sysadmin security
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups