Bonjour,

J'utilise un validateur custom pour valider mon ReCaptcha mais lors de l'envoie de la requete de validation au serveur de google le code que j'ai honteusement copié plante.


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 protected void vldCustom_ServerValidate(object source, ServerValidateEventArgs args)
        {
            string URLAuth = "http://www.google.com/recaptcha/api/verify";
 
            string postString = string.Format("privatekey={0}&remoteip={1}&challenge={2}&response{3}",
                "6LfXreISAAAAAIlF9Wfqo5sRnsUpL1doFCh_qp3E",
                Request.ServerVariables["LOCAL_ADDR"],
                Request.Form["recaptcha_challenge_field"],
                Request.Form["recaptcha_response_field"] );
 
            const string contentType = "application/x-www-form-urlencoded";
 
            System.Net.ServicePointManager.Expect100Continue = false;
 
            CookieContainer cookies = new CookieContainer();
            HttpWebRequest webRequest = WebRequest.Create(URLAuth) as HttpWebRequest;
            webRequest.Method = "POST";
            webRequest.ContentType = contentType;
            webRequest.CookieContainer = cookies;
            webRequest.ContentLength = postString.Length;
            webRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1";
            webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            webRequest.Referer = "https://accounts.craigslist.org";
 
            Stream requestStream = webRequest.GetRequestStream();
 
            StreamWriter requestWriter = new StreamWriter(requestStream);
            requestWriter.Write(postString);
 
            WebResponse response = webRequest.GetResponse();
            StreamReader responseReader = new StreamReader(response.GetResponseStream(),System.Text.Encoding.UTF8,true,100);
            string responseData = responseReader.ReadToEnd();
 
            requestWriter.Close();
            responseReader.Close();
            webRequest.GetResponse().Close();
        }
j'obtient l'erreur
You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.
sur la ligne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
WebResponse response = webRequest.GetResponse();
Je ne sais pas trop pourquoi mon stream me donne cette erreur ni comment la régler, avez vous déjà été confronté à cette erreur ?

Merci d'avance pour votre aide

Félix