2011-12-14 71 views
0

私の問題は、サーバーからの応答が0バイトであることです(これをチェックするにはFiddler2を使用しています)。PHPBB3フォーラムでスレッドを作成できません

画像: wtf

私がやっているもの:。

  1. ログインし、私はクッキーを取得します。
  2. スレッド作成
    public void CreateTopic(string subject, string message, string forumId) 
        { 
         HttpWebResponse response = null; 
         string source = string.Empty; 
         string lastClick= string.Empty; 
         string creationTime= string.Empty; 
         string formToken = string.Empty; 
    
         // GET 
         while(true) 
         { 
          webRequest = 
           (HttpWebRequest) HttpWebRequest.Create(Url + "posting.php?mode=post&f=" + forumId + "&sid=" + sid); 
          webRequest.KeepAlive = true; 
          webRequest.Method = "GET"; 
          webRequest.ContentType = "application/x-www-form-urlencoded"; 
          webRequest.Host = Url.Replace("http://", "").Replace("/", ""); 
          webRequest.CookieContainer = cookieJar; 
    
          ServicePointManager.Expect100Continue = false; 
    
          try 
          { 
           response = (HttpWebResponse) webRequest.GetResponse(); 
           UpdateSid(Url + "posting.php?mode=post&f=" + forumId + "&sid=" + sid); 
          } 
          catch (Exception ex) 
          { 
           continue; 
          } 
          break; 
         } 
    
         StreamReader streamReader = new StreamReader(response.GetResponseStream()); 
         source = streamReader.ReadToEnd(); 
         streamReader.Close(); 
    
         response.Close(); 
    
         // Get stuff 
         // last click 
         Match lastClickMatch = Regex.Match(source, "name=\"lastclick\" value=\"([0-9]{10})\" />"); 
         if (lastClickMatch.Success) lastClick = lastClickMatch.Groups[1].Value; 
    
         // creation time 
         Match creationTimeMatch = Regex.Match(source, "name=\"creation_time\" value=\"([0-9]{10})\" />"); 
         if (creationTimeMatch.Success) creationTime = creationTimeMatch.Groups[1].Value; 
    
         // form token 
         Match formTokenMatch = Regex.Match(source, "name=\"form_token\" value=\"(.{40})\" />"); 
         if (formTokenMatch.Success) formToken = formTokenMatch.Groups[1].Value; 
    
         // POST 
         webRequest = (HttpWebRequest)WebRequest.Create(Url + "posting.php?mode=post&f=" + forumId + "&sid=" + sid); 
         webRequest.Method = "POST"; 
         webRequest.ContentType = "application/x-www-form-urlencoded"; 
         webRequest.Host = Url.Replace("http://", "").Replace("/", ""); 
         webRequest.CookieContainer = cookieJar; 
         string data = "icon=&subject=" + Encode(subject) + "&addbbcode20=100&message=" + Encode(message) + "&attach_sig=on&post=Submit&lastclick=" + lastClick + "&creation_time=" + creationTime + "&form_token=" + formToken; 
    
         byte[] byte1 = Encoding.UTF8.GetBytes(data); 
         webRequest.ContentLength = byte1.Length; 
    
         ServicePointManager.Expect100Continue = false; 
    
         Stream stream = webRequest.GetRequestStream(); 
         stream.Write(byte1, 0, byte1.Length); 
         stream.Close(); 
    
         response = (HttpWebResponse)webRequest.GetResponse(); 
    
         UpdateSid(Url + "posting.php?mode=post&f=" + forumId + "&sid=" + sid); 
    
         response.Close(); 
        } 
    


私はシオマネキにこれを取得する: RAW:

POST http://stuff.com/posting.php?mode=post&f=8&sid=6d278be1e705fe0261f253bbc96ab7a4 
HTTP/1.1 Content-Type: application/x-www-form-urlencoded 
Host: stuff.com 
Cookie: phpbb3_goeyz_u=55443;phpbb3_goeyz_k=;phpbb3_goeyz_sid=6d278be1e705fe0261f253bbc96ab7a4 
Content-Length: 165 

icon=&subject=g&addbbcode20=100&message=d&attach_sig=on&post=Submit&lastclick=1323904393&creation_time=1323904393&form_token=b81c23e308f0bd3a0a73907efcc8c18e5dba0f7f 

応答RAW:

HTTP/1.1 302 Found 
Date: Wed, 14 Dec 2011 23:13:14 GMT 
Server: Apache/2.2.14 (Ubuntu) 
X-Powered-By: PHP/5.3.2-1ubuntu4.10 
Location: http://stuff.com/games.html 
Vary: Accept-Encoding 
Content-Length: 0 
Connection: close 
Content-Type: text/html 

私は何が起こっているか見当がつかないに。あなたが私を助けるなら、私は感謝します。私の英語はすみません。

+0

phpbb3ウェブサイトからスレッドを作成しようとすると、フィドラーには何が表示されますか? –

+0

レスポンスボディが0バイトを取得しない場合、レスポンスボディの長さは0です。これはContent-Lengthヘッダによって識別されます – CodeCaster

答えて

2

スレッドを作成しなかった理由を知りました。これは、チェック:

if ($user->data['is_bot']) 

あなたがボットにしたくない場合は、あなたがPOSTを送信する前に、8秒などのを待つ必要があります。

Thread.Sleep(8100); 

それは私のためにすべての問題を解決しました。

1

ステータスコード302が返されます。これは、サーバーが別のページ(例: "http://stuff.com/games.html")にリダイレクトしようとしていることを意味します。

+0

はい、スレッドは作成しません:) – carck3r

+0

あなたの例では、実際のものをリダイレクトすると、それが動作しない理由についての詳細情報が表示されることがあります。おそらくGETの代わりにPOSTを必要とするかもしれません。 –

3

私は、phpBBの3.0.9のソースにこのスニペットを見つけました:

203 // Check permissions 
204 if ($user->data['is_bot']) 
205 { 
206  redirect(append_sid("{$phpbb_root_path}index.$phpEx")); 
207 } 

だから、彼らはここにあなたのトリックを引っ張っている可能性があります。あなたはあなたがしようとしていることを許可されていますか?

とにかく、私はあなたのuser agentを変更したいかもしれないと思う:

webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.36 Safari/535.7"; 

これがデフォルトUserAgent値はnullあるので、おそらく起きるボット、として識別されていないに役立つかもしれません。

+0

助けてくれてありがとうございます。でもUserAgentを追加すると、以前と同じことが起こります。 – carck3r

+0

@ carck3rおそらく、同じバージョンのphpBB3をローカルにインストールして、同じ結果が得られることを確認してください。次に、phpBB3のデバッグを開始することができます。これは、何がうまくいかないかを知るために戦術的にposting.phpにいくつかの 'echo'を配置していることを意味します。 – CodeCaster

+0

はい、サーバー上でテストします。別のアイデアがある場合は、それを書いてください。今私は寝るつもりです。 – carck3r

関連する問題