2012-03-24 4 views
-1

연구를 위해이 웹 사이트 (http://www.prezup.info/index.php?page=films)에서 게시물 요청을 보내고 싶었습니다. 그러나 내가 게시물 요청을 할 때, 결과는 내가 기대했던 것 (연구 결과)이 아니라 메인 페이지입니다.왜이 POST 요청이 작동하지 않습니까?

누군가 내 요청에 무엇이 잘못되었는지 말해 줄 수 있습니까? 날짜가 포스트 요청 인수하고 그 형태가 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

응답이 예상 한 것과 다를 경우 웹 사이트가 다른 것을 브라우저에 보내고 다른 응답을 보내고 있는지 여부를 조사해야합니다. wireshark를 사용하여 보통 어떤 응답이 올지 확인하십시오. 당신은 웹 사이트가 무엇을 보내고 있는지를 알게 될 것입니다. – ata

답변

0

URL입니다, 그래서 당신의 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. –

관련 문제