2012-03-24 12 views
-1

私はこのウェブサイトで投稿を希望しました:http://www.prezup.info/index.php?page=filmsしかし、私が投稿要求をするとき、結果は私が期待したものではなく(研究の結果)、メインページです。なぜこのPOST要求が機能しないのですか?

誰かが私のリクエストに間違っていると教えてもらえますか?ここで

はコードです:日付は、POSTリクエストの引数であり、あなたのURLが間違っているので、フォームは、http://www.prezup.info/index.php?page=films&action=listにPOST要求を行い、そのURL

public string POST() 
    { 
     string data = "motcle=terminator&ok.x=17&ok.y=16"; 
     string Reponse = String.Empty; 
     string contenttype = "application/x-www-form-urlencoded"; 
     string useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729; .NET4.0E)"; 
     string host = "www.prezup.info"; 
     string url = "http://www.prezup.info/index.php?page=films"; 
     string method = "POST"; 

     StreamWriter Sw = null; // Pour écrire les données 
     StreamReader Sr = null; // Pour lire les données 
     try 
     { 
      HttpWebRequest Req = (HttpWebRequest)WebRequest.Create(url); 
      Req.Method = method; // POST ou GET 
      Req.Host = host; 
      Req.KeepAlive = true; 
      Req.UserAgent = useragent; 
      Req.CookieContainer = cookieJar; 

      ASCIIEncoding encoding = new ASCIIEncoding(); 
      byte[] byte1 = encoding.GetBytes(data); 
      Req.ContentType = contenttype; 
      Req.ContentLength = byte1.Length; // La longueur des données 
      Stream newStream = Req.GetRequestStream(); 
      newStream.Write(byte1, 0, byte1.Length); 
      newStream.Close(); 

      Sr = new StreamReader(((HttpWebResponse)Req.GetResponse()).GetResponseStream()); 
      Reponse = Sr.ReadToEnd(); // On choppe la réponse 
      int cookieCount = cookieJar.Count; 
      Sr.Close(); // Et on ferme 
      Sw = null; 
     } 
     catch (Exception e) // En cas d'exception 
     { 
      if (Sw != null) // Si le flux est ouvert, on le ferme 
       Sw.Close(); 
      if (Sr != null) 
       Sr.Close(); 

      Reponse = e.Message; 
     } 
     return Reponse; 
    } 
+0

ご質問に対する回答ではありません。 1.あなたはそのStreamWriterオブジェクトを使用していないことを知っていますか? 2.使い捨てオブジェクトを処分し、 'using'ステートメントを使用して(http://msdn.microsoft.com/en-us/library/yh598w02.aspx)[エレガントに]行います。 –

+0

それは動作するはずです。どのようなエラーが表示されますか? –

+0

応答が期待どおりでない場合は、Webサイトがブラウザに何か他のものを送っているのか、あなたに別の応答を送るのかを調べなければなりません。 wiresharkを使用して、どのような応答が通常来るかを確認してください。 – ata

答えて

0

をURL。変更:

string url = "http://www.prezup.info/index.php?page=films"; 

string url = "http://www.prezup.info/index.php?page=films&action=list"; 

し、それがうまくいきます。

+0

それは間違っていたものです。大いに感謝する! –

+0

@JérémieDjidjiL'Amoroso、yw。 –

関連する問題