HTTPWebRequest et credential

dufoli Messages postés 13 Date d'inscription samedi 6 décembre 2003 Statut Membre Dernière intervention 17 mai 2006 - 10 févr. 2005 à 11:16
dufoli Messages postés 13 Date d'inscription samedi 6 décembre 2003 Statut Membre Dernière intervention 17 mai 2006 - 11 févr. 2005 à 13:19
Je voudrai recréer cet en-tête et ce qui me pose problème c'est : "Autorization"
J'utilise HttpWebRequest, mais malgré avoir rempli un objet pour l authorisation elle reste vide dans ethereal ce qui me laisse penser que l authorisation ne marche pas.
quelqu un sait il comment cela fonctionne
je voudrait une requete de ce type:
POST /QuickPlace...
Accept: image/gif...
Referer: http://...
Accept-Language: fr
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible;...)
Host: webtc...
Content-Length: 1209
Connection: Keep-Alive
Cache-Control: no-cache
Authorization: Basic "..."
et pour cela j ai fait le code suivant:
   ASCIIEncoding encoding=new ASCIIEncoding();
   //string postData="%%ModDate="+ModDate;
   



   string postData = "test";
   //postData += ("&username="+strName);
   byte[]  data = encoding.GetBytes(postData);
  
   // Prepare web request...
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://webtc.paris.ensam.fr/QuickPlace/am-pfewiki/Main.nsf/2a1fb3846ca143220525670800167222/406ac6104bd821d30525670800167200/?EditDocument");
    //myRequest.PreAuthenticate=true;
    myRequest.Method = "POST";
   myRequest.Accept="image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
   myRequest.Referer= "http://webtc.paris.ensam.fr/QuickPlace/am-pfewiki/Main.nsf/2a1fb3846ca143220525670800167222/406ac6104bd821d30525670800167200/?EditDocument";
   myRequest.ContentType="application/x-www-form-urlencoded";
   //myRequest.TransferEncoding = "gzip, deflate";
   myRequest.ContentLength = data.Length;
   myRequest.KeepAlive = true;
   //myRequest.UserAgent="Basic b2R1Zm91dfnjkWZlZHVmZQ==";
   //myRequest.Acceptlanguage
      NetworkCredential myCred new NetworkCredential("monnom","monpass","");//SecurelyStoredDomain param 3
    
   CredentialCache myCache = new CredentialCache();
    
   myCache.Add(new Uri("http://www.paris.ensam.fr/QuickPlace/am-pfewiki"), "Basic", myCred);
   myRequest.Credentials = myCache;
    //WebResponse myWebResponse = myRequest.GetResponse();
   
   Stream newStream=myRequest.GetRequestStream();
   // Send the data.
   newStream.Write(data,0,data.Length);
   newStream.Close();
   

1 réponse

dufoli Messages postés 13 Date d'inscription samedi 6 décembre 2003 Statut Membre Dernière intervention 17 mai 2006
11 févr. 2005 à 13:19
le probleme esr resolue en fait il fallait utiliser :



string cre = String.Format("{0}:{1}", this.textBox1.Text, this.textBox2.Text);

byte [] bytes = Encoding.ASCII.GetBytes(cre);

string base64 = Convert.ToBase64String(bytes);

myRequest.Headers.Add("Authorization", "basic " + base64);



et pas le system de credentials
0
Rejoignez-nous