Bonjour à tous,

Alors voilà mon problème :

Je travail avec c++ builder 3 et j'utilise le composant TNMHTTP qui permet d'opérer des transferts HTTP via Internet ou un intranet avec GET et POST.
Cela fonctionne très bien, sauf dans le cas ou je dois passer au travers d'un proxy avec identification (login et mot de passe).

Il y trois solutions :

Le première consiste à renseigner les propriétés suivantes:
//Premiere solution
// NMHTTP1->HeaderInfo->UserId = "username";
// NMHTTP1->HeaderInfo->Password = "password";

La seconde à envoyer dans le "header" les infos. d'identifications:
//seconde solution
void __fastcall TForm1::NMHTTP1AboutToSend(TObject *Sender)
{
NMHTTP1->SendHeader->Insert(2, "Proxy-authorization:" + EncodeAuth("username", "password"));

}

Ces deux solutions ne fonctionne pas, j'ai systématiquement dans le "body" la réponse suivante :
<html><body><font size="5" color="#FF0000"><br><b>HTTP Proxy: Access denied!</b></font><hr>
<b>Description:</b> A password is required by HTTP Service.
<hr><font size="2"><font color="#FF0000">Proxy</font><font color="#0000FF">+</font> 3.00 (Build #264), Date: Thu, 06 Sep 2007 09:37:12 GMT</font>

Ci dessous ce trouve le code qui me permet de faire mes tests

La troisième solution se serai de re écrire mon code dans un autre langage … ? Solution extrême parce que je manque de temps !!!

Mais avant d'en arriver la je voudrais savoir ou je me trompe pour ne pas mourir idiot !!!

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
NMHTTP1->TimeOut = 5000;
NMHTTP1->InputFileMode = false;
NMHTTP1->OutputFileMode = false;
NMHTTP1->ReportLevel = Status_Basic;

NMHTTP1->Proxy = "xxx.xxx.xxx.xxx";
NMHTTP1->ProxyPort = 9999;

// NMHTTP1->HeaderInfo->Cookie = "";
// NMHTTP1->HeaderInfo->LocalMailAddress = "";
// NMHTTP1->HeaderInfo->LocalProgram = "";
// NMHTTP1->HeaderInfo->Referer = "";

//Premiere solution
// NMHTTP1->HeaderInfo->UserId = "username";
// NMHTTP1->HeaderInfo->Password = "password";

NMHTTP1->Get("http://xxx.xxx.xxx.xxx/reptemp/page.php?&param1=xxx&param2=xxx&param3=xxx&param4=xxx&param5=xxx");

Memo1->Text = NMHTTP1->Body;
Memo2->Text = NMHTTP1->Header;

}
//---------------------------------------------------------------------------

String __fastcall TForm1::EncodeAuth(String username, String password)
{

TNMUUProcessor *uu;

TStringStream *si,
*so;

String decoded,
encoded,
result;


decoded = username + ':' + password;
encoded.SetLength(20 * decoded.Length());

uu = new TNMUUProcessor(NULL);
si = new TStringStream(decoded);
so = new TStringStream(encoded);

uu->InputStream = si;
uu->OutputStream = so;
uu->Method = uuMime;
uu->Encode();

result = so->ReadString(255);
result = result.SubString(1, result.Length() - 2);

delete so;
delete si;
delete uu;

return result;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMHTTP1AboutToSend(TObject *Sender)
{
//Deuxieme solution
NMHTTP1->SendHeader->Insert(2, "Proxy-authorization:" + EncodeAuth("username", "password"));

}
//---------------------------------------------------------------------------