Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1462 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  [MFC] WinInet -> Proxy

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[MFC] WinInet -> Proxy

n°318975
McGiver
Posté le 27-02-2003 à 10:21:49  profilanswer
 

Bonjour, je dois créer une fonction retournant le contenu d'une adresse http. (Le code source d'une page)
Cela fonctionne sans probleme tant que je ne passe pas par le proxy securisé de la boite. Il me retourne invariablement une erreur 407 (authentification error !)
 
Si quelqu'un pouvais m'aider :
Voici le code :
 

Code :
  1. int HttpCall(
  2. const char * serveur,
  3. int port,
  4. const char * sProcess,
  5. const char * qString,
  6. char * buffer,
  7. int taille,
  8. const char * proxyServeur = NULL,
  9. int proxyPort = NULL,
  10. const char * proxyLogin = NULL,
  11. const char * proxyMdP = NULL
  12. )
  13. {
  14. long nbCharLus;
  15. char bufTemp[4096];
  16. int i;
  17. char proxyChaine[128];
  18. sprintf(proxyChaine, "http://%s:%d", proxyServeur, proxyPort);
  19. CInternetSession * session;
  20. CString process = sProcess;
  21. CString queryString = qString;
  22. if (queryString.GetLength() > 0)
  23.  process += '?' + queryString;
  24. CString strHeaders =  "Accept: text/\r\n";
  25.   strHeaders += "User-Agent: HttpCall\r\n";
  26.   strHeaders += "Accept-Language: fr-fr\r\n";
  27. DWORD dwRet = 0;
  28. if (proxyServeur == NULL)
  29.  session = new CInternetSession((LPCTSTR) "SessionHttpCall", (DWORD) 1, (DWORD) INTERNET_OPEN_TYPE_DIRECT, (LPCTSTR) NULL, (LPCTSTR) NULL, (DWORD) 0);
  30. else
  31. {
  32.  session = new CInternetSession((LPCTSTR) "SessionHttpCall", (DWORD) 1, (DWORD) INTERNET_OPEN_TYPE_PROXY, (LPCTSTR) proxyChaine, (LPCTSTR) NULL, (DWORD) INTERNET_FLAG_DONT_CACHE);
  33.  try
  34.  {
  35.   if (proxyLogin != NULL)
  36.    session->SetOption((DWORD) INTERNET_OPTION_PROXY_USERNAME, (LPVOID) proxyLogin, (DWORD) strlen(proxyLogin) + 1);
  37.   if (proxyMdP != NULL)
  38.    session->SetOption((DWORD) INTERNET_OPTION_PROXY_PASSWORD, (LPVOID) proxyMdP, (DWORD) strlen(proxyMdP) + 1);
  39.  }
  40.  catch (CInternetException * pEx)
  41.  {
  42.   return 500;
  43.  }
  44. }
  45. CHttpConnection * pServer = NULL;
  46. CHttpFile * pFile = NULL;
  47. try
  48. {
  49.  pServer = session->GetHttpConnection((CString) serveur, (INTERNET_PORT) port);
  50.  pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, process);
  51.  pFile->AddRequestHeaders(strHeaders);
  52.  pFile->SendRequest();
  53.  pFile->QueryInfoStatusCode(dwRet);
  54.  if (dwRet < 200 || dwRet > 299)
  55.   return dwRet;
  56.  nbCharLus = pFile->Read(bufTemp, 4096);
  57.  if (nbCharLus < taille)
  58.   taille = nbCharLus;
  59.  for (i = 0; i < taille - 1; i++)
  60.   buffer[i] = bufTemp[i];
  61.  buffer[taille - 1] = '\0';
  62.  delete pFile;
  63.  delete pServer;
  64. }
  65. catch (CInternetException * pEx)
  66. {
  67.  buffer[0] = '\0';
  68.  return dwRet;
  69. }
  70. session->Close();
  71. return dwRet;
  72. }


Message édité par McGiver le 07-03-2003 à 13:57:10
mood
Publicité
Posté le 27-02-2003 à 10:21:49  profilanswer
 

n°325964
McGiver
Posté le 07-03-2003 à 13:58:19  profilanswer
 

:sleep: S'il vous plais...  :sleep:


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  [MFC] WinInet -> Proxy

 

Sujets relatifs
[MFC] CAsyncSocket ....[MFC] Ajouter des elements a une CListView ?
[C/C++][Win32] PreTranslateMessage sans MFC: detect key pressles MFC en mode console?
[MFC] RichEdit: SetWordCharFormat == SetSelectionCharFormat ?[MFC] Comment savoir si une fenêtre MDI est partiellement visible ???
VC++, MFC : zigouiller un repertoire non vide...[MFC] Masquer le curseur de souris
MFC Visual C++ et Excel[C++/MFC]Je voudrais faire ...
Plus de sujets relatifs à : [MFC] WinInet -> Proxy


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR