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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Proxy authentication failed error code is 407. Same code works fine without proxy.

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

Scheduled Pinned Locked Moved C / C++ / MFC
helpcomsysadminsecurity
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amar_mhetre
    wrote on last edited by
    #1

    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

    R 1 Reply Last reply
    0
    • 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

      R Offline
      R Offline
      Rahul Vaishnav
      wrote on last edited by
      #2

      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));
      
      A 1 Reply Last reply
      0
      • R Rahul Vaishnav

        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));
        
        A Offline
        A Offline
        amar_mhetre
        wrote on last edited by
        #3

        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.

        R 1 Reply Last reply
        0
        • 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.

          R Offline
          R Offline
          Rahul Vaishnav
          wrote on last edited by
          #4

          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[^]

          A 1 Reply Last reply
          0
          • R Rahul Vaishnav

            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[^]

            A Offline
            A Offline
            amar_mhetre
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

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