2012-04-23 7 views
0

私はどのようにしてSpecial:Exportを自分の目的に使用できるのですか?HTTP特別注文のページを入手する:

string request = "POST en.wikipedia.org/w/index.php?title=Special:Export&action=submit HTTP/1.1\r\n" 
       "Host: en.wikipedia.org\r\n" 
       "Content-Length: 32\r\n" 
       "Content-Type: application/x-www-form-urlencoded\r\n" 
       "Connection: close\r\n\r\n" 
       "catname=&pages=ukraine&curonly=1"; 

が、それは誤りについて私にページをレンダリングする:私は私のアプリから次のヘッダを送信

HTTP/1.0 400 Bad Request Server: squid/2.7.STABLE9 Date: Mon, 23 Apr 2012 14:45:12 GMT Content-Type: text/html Content-Length: 3111 X-Squid-Error: ERR_INVALID_URL 0 X-Cache: MISS from amssq46.esams.wikimedia.org X-Cache-Lookup: NONE from amssq46.esams.wikimedia.org:80 Connection: close

は私が翻訳を助けるためにinwikiのリンクを交換するためのツールを作成する必要があります。私はそのようなツールがすでに存在していると確信していますが、私はそれを自分でやりたいのです。

EDITED:私はC++とソケットを使用しています。

EDITED:新しい要求:

string request = "POST https://en.wikipedia.org/w/index.php?title=Special:Export&action=submit HTTP/1.1\r\n" 
//string request = "GET https://en.wikipedia.org/w/index.php?title=Special:Export&pages=ukraine&curonly=1\r\n" 
       "Host: en.wikipedia.org\r\n" 
       "User-Agent: MyCoolTool\r\n" 
       "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" 
       "Accept-Language: en-us,en;q=0.5\r\n" 
       "Accept-Encoding: gzip, deflate\r\n" 
       "Content-Length: 32\r\n" 
       "Content-Type: application/x-www-form-urlencoded\r\n" 
       "Connection: close\r\n\r\n" 
       "catname=&pages=Ukraine&curonly=1"; 

私は私はあなたが高い使用することを提案した理由がある

Scripts should use an informative User-Agent string with contact information, or they may be IP-blocked without notice.

+0

あなたはどの言語を使用していますか?既にそれを行うライブラリがあるかもしれません。なぜ生のHTTPリクエストを書いていますか?あなたの環境にはHTTP要求を行うためのより良い方法はありませんか? – svick

+0

@svick、ヘッダーはヘッダー、言語は問題ありません。 – Yola

答えて

1

持っ

string request = "GET http://en.wikipedia.org/wiki/Ukraine\r\n" ... 
       "User-Agent: YolaTool/0.1\r\n" ... 

だけのページに取得しようHTTPを直接サポートするレベルネットワーキングライブラリ:この方法では、低レベルの詳細に対処する必要がなくなります。彼らが正しいことを確かめてください。

POST http://en.wikipedia.org/w/index.php?title=Special:Export&action=submit HTTP/1.1 

、より一般的に、絶対パスまたは:

POST /w/index.php?title=Special:Export&action=submit HTTP/1.1 

を参照してください、あなたの場合は

は、問題がPOSTキーワードの後、いずれかの絶対URIが存在しなければならないということですRFC 2616, §5.1.2

あなたがこの問題を修正する場合は、403エラーになりますが、今回はエラーメッセージは、この問題を解決するために何をすべきかについては明らかである:

Scripts should use an informative User-Agent string with contact information, or they may be IP-blocked without notice.

WikiMedia User-Agent policyを参照してください。

+0

質問が更新されました。ボットユーザーエージェントをどこかに登録する必要がありますか? – Yola

+0

いいえ、そうではありません。一般的なブロックされたユーザーエージェント(wgetのデフォルトのユーザーエージェントのようなもの)と一致しない限り、ほとんどすべてをそこに置くことができます。 – svick

+0

それでも動作しませんが、+1))IPで問題があるかもしれません、あなたは特別な質問をする権利を知っていますか:輸出、私は91.198.174.225を使用します – Yola

関連する問題