糞ネット弁慶 日本声優統計学会/声優統計についてはこちら
Day:2007.07.02 20:42 Cat:コンピュータ的なこと HTTP接続をしてHTMLを取得するrubyクライアントを作っていたときのメモ。 Cookieの解析の部分で躓いた。Cookieに何故かサーバ側ではセットしてない文字列が含まれているのだ。 UID=hoge;expires=Tue, 1-Jan-2030 00:00:00 GMT;, PASS=password; このままHTTPヘッダの「Cookie」にセットしてしまうとうまくCookieが処理されない。どうやら「PASS」の前に入っている「, 」がゴミになっているようだ。サーバ側では特にセットしていないのに、何故こんなものが入るんだ?と散々悩んだのだが、どうやらサーバ側で「Set-Cookie」を複数回 print すると、その度にカンマが出力されることが判明。Cookieのデータは'name'単位ではカンマ区切り
id:mzp:20070214:1171465153の続き。RubyのNet::HTTPでのクッキーの扱い方。 クッキーの受信 クッキは、Set-Cookie:というフィールドに書かれている。 ただし、複数のSet-Cookieフィールドが存在することが普通なので、Net::HTTP#get_fieldsを使って配列の形で取得する。 require 'net/http' Net::HTTP.start('www.tohoho-web.com'){|http| response, = http.get '/cgi/wwwcook.cgi' p response.get_fields('Set-Cookie') } 実行例: ["KAISUU=2; expires=Tue, 1-Jan-2030 00:00:00 GMT;", "HIZUKE=2007%2F02%2F16%2021%3A46%
プログラミングもだいぶ身に付いてきたような気がするので、習作として何か作ろうと考えていたところ、Twittterを使ったサービスを思いついた。 早速『Twitter!―Twitter APIガイドブック』を買って読んでみると、『Ruby Twitter Gem』なる便利なライブラリがあるのが分かったので試してみた。 インストールはいたって簡単。 gem install twitter Twitterへ投稿するには以下のようにやるとよい。 irbを起動。 irb ライブラリーを呼び出し、インスタンスを生成した後、updateメソッドを実行。 require 'twitter' twit = Twitter::Base.new("email", "password") twit.update('testing Ruby Twitter Gem') 無事反映された。 ライブラリーは他にも『Tw
Streaming APIとは TwitterのStreaming APIをご存知でしょうか。 Twitter API Wiki / Streaming API Documentation 2009年4月頃から試験的に公開されているAPIなので、ご存知な方も多いと思います。2009年8月現在でまだαテスト中ですが、これを利用すると、push型でリアルタイムに情報を受け取ることができます。 TwitterのAPIは基本的にpull型なので、クライアントが能動的にリクエストを発行しなければ情報を受け取ることができません。しかし、1時間あたりのリクエスト回数、1リクエストあたりの最大データ数など、APIには様々な制限がかけられていますので、例えばリアルタイム性の必要なプログラムや、大量のtweetsが必要な統計プログラムなどの用途で通常のAPIを利用するのは厳しいものがあります。 そのような時は
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く