McGiver | 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 :
- int HttpCall(
- const char * serveur,
- int port,
- const char * sProcess,
- const char * qString,
- char * buffer,
- int taille,
- const char * proxyServeur = NULL,
- int proxyPort = NULL,
- const char * proxyLogin = NULL,
- const char * proxyMdP = NULL
- )
- {
- long nbCharLus;
- char bufTemp[4096];
- int i;
- char proxyChaine[128];
- sprintf(proxyChaine, "http://%s:%d", proxyServeur, proxyPort);
- CInternetSession * session;
- CString process = sProcess;
- CString queryString = qString;
- if (queryString.GetLength() > 0)
- process += '?' + queryString;
- CString strHeaders = "Accept: text/\r\n";
- strHeaders += "User-Agent: HttpCall\r\n";
- strHeaders += "Accept-Language: fr-fr\r\n";
- DWORD dwRet = 0;
- if (proxyServeur == NULL)
- session = new CInternetSession((LPCTSTR) "SessionHttpCall", (DWORD) 1, (DWORD) INTERNET_OPEN_TYPE_DIRECT, (LPCTSTR) NULL, (LPCTSTR) NULL, (DWORD) 0);
- else
- {
- session = new CInternetSession((LPCTSTR) "SessionHttpCall", (DWORD) 1, (DWORD) INTERNET_OPEN_TYPE_PROXY, (LPCTSTR) proxyChaine, (LPCTSTR) NULL, (DWORD) INTERNET_FLAG_DONT_CACHE);
- try
- {
- if (proxyLogin != NULL)
- session->SetOption((DWORD) INTERNET_OPTION_PROXY_USERNAME, (LPVOID) proxyLogin, (DWORD) strlen(proxyLogin) + 1);
- if (proxyMdP != NULL)
- session->SetOption((DWORD) INTERNET_OPTION_PROXY_PASSWORD, (LPVOID) proxyMdP, (DWORD) strlen(proxyMdP) + 1);
- }
- catch (CInternetException * pEx)
- {
- return 500;
- }
- }
- CHttpConnection * pServer = NULL;
- CHttpFile * pFile = NULL;
- try
- {
- pServer = session->GetHttpConnection((CString) serveur, (INTERNET_PORT) port);
- pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, process);
- pFile->AddRequestHeaders(strHeaders);
- pFile->SendRequest();
- pFile->QueryInfoStatusCode(dwRet);
- if (dwRet < 200 || dwRet > 299)
- return dwRet;
- nbCharLus = pFile->Read(bufTemp, 4096);
- if (nbCharLus < taille)
- taille = nbCharLus;
- for (i = 0; i < taille - 1; i++)
- buffer[i] = bufTemp[i];
- buffer[taille - 1] = '\0';
- delete pFile;
- delete pServer;
- }
- catch (CInternetException * pEx)
- {
- buffer[0] = '\0';
- return dwRet;
- }
- session->Close();
- return dwRet;
- }
|
Message édité par McGiver le 07-03-2003 à 13:57:10
|