IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Requete HTTP POST multipart/form-data avec CF qui n'aboutie pas


Sujet :

C#

  1. #1
    Candidat au Club
    Profil pro
    Ingénieur
    Inscrit en
    Novembre 2008
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Ingénieur

    Informations forums :
    Inscription : Novembre 2008
    Messages : 4
    Points : 4
    Points
    4
    Par défaut Requete HTTP POST multipart/form-data avec CF qui n'aboutie pas
    Bonjour,

    Je développe une application sur windows mobile pour prendre une photo et l'envoyer directement sur un serveur web via un formulaire.
    Je dois donc construire une requête http POST en y joignant le fichier.

    J'ai adapté une source trouvée sur le net, la requête semble bien construite mais ne réussit pas.
    J'ai réussi à intercepter une requête et il semble qu'elle ne se finisse pas. (pas de boundary en fin)

    Voici le code que j'utilise:
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
     
    try
    {
         //Envoi de la requete
         HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://www.novaduo.com/");
     
         // Set the 'Method' property of the 'Webrequest' to 'POST'.
         myReq.Method = "POST";
         myReq.UserAgent = this.cUserAgent;
         myReq.Referer = "http://www.lavieestunlongfleuve.com";
     
     
         myReq.ContentType = "multipart/form-data; boundary=" + this.cMultiPartBoundary;
     
     
     
     
     
         string postData = "";
         postData = cMultiPartBoundary + "\r\n";
         postData += "Content-Disposition: form-data; name=\"add_job\"" + "\r\n";
         postData += "Envoyer" + "\r\n" + cMultiPartBoundary + "\r\n";
         postData += "Content-Disposition: form-data; name=\"email\"" + "\r\n" + "\r\n";
         postData += "canssens@gmail.com\r\n" + cMultiPartBoundary + "\r\n";
         postData += "Content-Disposition: form-data; name=\"fichier\"; filename=\"photo.jpg\"" + "\r\n";
         postData += "Content-Type: image/jpeg\r\n" + "\r\n";
     
         ASCIIEncoding encoding = new ASCIIEncoding();
         byte[] data = encoding.GetBytes(postData);
     
     
     
         //i then attach the file to be uploaded to this byte array
         byte[] byte2 = new byte[4096];
         int BlockSize;
     
         MemoryStream TempStream = new MemoryStream();
         FileStream myFileStream = new FileStream(@"\Storage Card\My Pictures\novaduo.jpg", FileMode.Open); //
     
         do
         {
              BlockSize = myFileStream.Read(byte2, 0, 4096);
              if (BlockSize > 0) TempStream.Write(byte2, 0, BlockSize);
     
     
         } while (BlockSize > 0);
     
         byte[] data2 = TempStream.ToArray();
     
         //I then join the two byte arrays together and close the Http POST request byte array
     
         postData = "\r\n" + cMultiPartBoundary + "\r\n";
         byte[] data3 = encoding.GetBytes(postData);
     
         //return the complete binary data
         byte[] dataTotal = new Byte[data.Length + data2.Length + data3.Length];
         data.CopyTo(dataTotal, 0);
         data2.CopyTo(dataTotal, data.Length);
         data3.CopyTo(dataTotal, (data.Length + data2.Length));
     
     
         //The request NOW
         myReq.ContentLength = dataTotal.Length;
     
         Stream myStream = myReq.GetRequestStream();
     
         myStream.Write(dataTotal, 0, dataTotal.Length);
         myStream.Close();
     
     
         MessageBox.Show("done", this.Text);
     
         }
         catch (Exception e2)
         {
              MessageBox.Show("Erreur " + e2, this.Text);
              Console.WriteLine("{0} Exception caught.", e2);
         }


    Voici ma requête
    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
     
    POST / HTTP/1.1
    Connection: Keep-Alive
    Expect: 100-continue
    Host: 82.225.132.107
    Referer: http://www.lavieestunlongfleuve.com
    User-Agent: SAMSUNG-SGH-i600V/1.0 (compatible; MSIE 6.0; Windows CE; IEMobile 6.12)
    Content-Length: 47282
    Content-Type: multipart/form-data; boundary=-----------------------------7cf2a327f01ae
    X-BlueCoat-Via: CC84AC59F19475DD
    X-Forwarded-For: 10.186.122.206
    X-ICAP-Version: 1.0
    X-Nokia-BEARER: UMTS
    X-Nokia-CONNECTION-MODE: TCP
    X-Nokia-Gateway-Id: NWG/4.1/Build79
    X-Nokia-Gid: 276289016239316
    X-Nokia-Ipaddress: 10.186.122.206
     
    -----------------------------7cf2a327f01ae
    Content-Disposition: form-data; name="add_job"
    Envoyer
    -----------------------------7cf2a327f01ae
    Content-Disposition: form-data; name="email"
     
    caXXXXXXXXil.com
    -----------------------------7cf2a327f01ae
    Content-Disposition: form-data; name="fichierTitle"
     
    novaduo.jpg
    -----------------------------7cf2a327f01ae
    Content-Disposition: form-data; name="fichier"
    Content-Type: image/jpeg
     
    ÿØÿà...
    Le fichier semble se dérouler, mais pas entièrement... et il n'y a pas de boundary en fin de requête.

    Je ne vois pas pourquoi la requête ne se termine pas, elle s'interrompre durant le fichier.



    Auriez-vous une idée pour me débloquer?


    Charles

  2. #2
    Candidat au Club
    Profil pro
    Ingénieur
    Inscrit en
    Novembre 2008
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Ingénieur

    Informations forums :
    Inscription : Novembre 2008
    Messages : 4
    Points : 4
    Points
    4
    Par défaut
    je reviens vers vous, car j'ai avancé, j'ai finalement entrepris de calqué la requete type générée par mozilla.
    Et ma requete via mon application et identique mais elle n'aboutie pas.
    En bref je ne comprends pas.

    Voici la requete via mon application Windows mobile :
    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
    38
    39
     
    Cache-Control: max-age=259200
    Connection: keep-alive
    Via: 1.1 proxylanVDA2:80 (squid/2.5.STABLE9), 1.0 proxydmzvda:80 (squid/2.5.STABLE9)
    Expect: 100-continue
    Host: 82.225.132.207
    Referer: http://www.lavieestunlongfleuve.com
    User-Agent: SAMSUNG-SGH-i600V/1.0 (compatible; MSIE 6.0; Windows CE; IEMobile 6.12)
    Content-Length: 1030
    Content-Type: multipart/form-data; boundary=-----------------------------41184676334
    X-Forwarded-For: 142.218.61.229, unknown
     
    -----------------------------41184676334
    Content-Disposition: form-data; name="email"
     
    canssens@gmail.com
    -----------------------------41184676334
    Content-Disposition: form-data; name="fichier"; filename="novaduo.jpg"
    Content-Type: image/jpeg
     
    ÿØÿàJFIF``ÿÛC
     $.' ",#(7),01444'9=82<.342ÿÛC
    2!!22222222222222222222222222222222222222222222222222ÿ"ÿÄ
     
    ÿĵ}!1AQa"q2#B±ÁRÑð$3br
    %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
     
    ¢£¤¥¦§¨©ª²³´µ¶•¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ
     
    ÿĵw!1AQaq"B¡±Á #3RðbrÑ
    $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
     
    ¢£¤¥¦§¨©ª²³´µ¶•¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÚ
    ?ùþ( ÿÙ
    -----------------------------41184676334
    Content-Disposition: form-data; name="add_job"
     
    Envoyer
    -----------------------------41184676334--

    voici la requete via mozilla
    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
    38
    39
    40
    41
    42
    POST / HTTP/1.0
    Cache-Control: max-age=259200
    Connection: keep-alive
    Via: 1.1 proxylanVDA1:80 (squid/2.5.STABLE9), 1.0 proxydmzvda:80 (squid/2.5.STABLE9)
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Accept-Encoding: gzip,deflate
    Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
    Host: 82.225.132.207
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3
    Content-Length: 1030
    Content-Type: multipart/form-data; boundary=---------------------------41184676334
    Keep-Alive: 300
    X-Forwarded-For: 142.218.61.229, unknown
     
    -----------------------------41184676334
    Content-Disposition: form-data; name="email"
     
    <a href="mailto:canssens@gmail.com">canssens@gmail.com</a>
    -----------------------------41184676334
    Content-Disposition: form-data; name="fichier"; filename="novaduo.jpg"
    Content-Type: image/jpeg
     
    ÿØÿàJFIF``ÿÛC
     $.' ",#(7),01444'9=82<.342ÿÛC
    2!!22222222222222222222222222222222222222222222222222ÿ"ÿÄ
     
    ÿĵ}!1AQa"q2#B±ÁRÑð$3br
    %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
     
    ¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ
     
    ÿĵw!1AQaq"B¡±Á #3RðbrÑ
    $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
     
    ¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÚ
    ?ùþ(*ÿÙ
    -----------------------------41184676334
    Content-Disposition: form-data; name="add_job"
     
    Envoyer
    -----------------------------41184676334--

  3. #3
    Candidat au Club
    Profil pro
    Ingénieur
    Inscrit en
    Novembre 2008
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Ingénieur

    Informations forums :
    Inscription : Novembre 2008
    Messages : 4
    Points : 4
    Points
    4
    Par défaut
    Bon j'ai trouvé une partie de la solution.



    Cela fonctionne maintenant en envoyant une image d'un pixel noir.



    Pour une plus grosse image, cela ne passe pas sur le réseau 3G de SFR.

    Mais lorsque je suis branché sur le wifi avec Windows Mobile, l'image est bien envoyé.



    Ca ne ressemble pas à un timeout vu que j'ai bien la réponse à ma requette http, j'espere que SFR ne filtre pas l'envoi d'image.

Discussions similaires

  1. Serialize POST multipart/form-data
    Par seb-65 dans le forum jQuery
    Réponses: 2
    Dernier message: 06/08/2012, 10h47
  2. Soucis avec un POST enctype="multipart/form-data"
    Par Goupo dans le forum Langage
    Réponses: 2
    Dernier message: 17/04/2009, 17h21
  3. [Flash] Post avec LoadVars en multipart/form-data
    Par ViveLesQuads dans le forum Flash
    Réponses: 6
    Dernier message: 16/01/2007, 17h56
  4. Réponses: 15
    Dernier message: 26/10/2006, 10h42
  5. BUG avec form multipart/form-data
    Par LEF97 dans le forum Langage
    Réponses: 2
    Dernier message: 11/06/2006, 19h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo