PG_2008夏
夏の勉強。
遅延評価勉強でもするかってことで
目標を用意
- もの テキストブラウザ
・by C# & by ruby
・プロキシ設定できること
- じかん 8月中
とりあえずhttp関連のライブラリを一度さわっておくのが目的。
基本がわかりゃRSSリーダの展開とかもすぐできるだろうし
# web系PGに手をつけようとも思ってるけど、サバ立てする気力がまだない。。
« 2008年06月 | メイン | 2009年02月 »
夏の勉強。
遅延評価勉強でもするかってことで
目標を用意
- もの テキストブラウザ
・by C# & by ruby
・プロキシ設定できること
- じかん 8月中
とりあえずhttp関連のライブラリを一度さわっておくのが目的。
基本がわかりゃRSSリーダの展開とかもすぐできるだろうし
# web系PGに手をつけようとも思ってるけど、サバ立てする気力がまだない。。
勉強。
とりあえず参考URLコピペ加工。
// 参考 http://www.divakk.co.jp/aoyagi/csharp_winexe_05.html using System; using System.IO; using System.Net; class c { public static void Main() { UrlOpen("http://chrono.s9.xrea.com/"); } private static void UrlOpen(string url) { WebRequest req = WebRequest.Create( url ); WebResponse rsp = req.GetResponse(); Stream stm = rsp.GetResponseStream(); if (stm != null) { StreamReader reader = new StreamReader(stm, System.Text.Encoding.GetEncoding("Shift_JIS")); string readText = reader.ReadToEnd(); Console.WriteLine(readText); stm.Close(); } rsp.Close(); } }ruby
# 参考 http://www.ruby-lang.org/ja/man/html/net_http.html require 'net/http' Net::HTTP.version_1_2 # おまじない Net::HTTP.start("chrono.s9.xrea.com", 80) {|http| response = http.get('/index.html') puts response.body }
proxyの設定
C#// 参考 http://dobon.net/vb/dotnet/internet/useproxy.html //// ----------------------------------------------------------------- //// プロキシの設定 string str_proxy = "http://localhost:8080"; string str_url = "http://www.yahoo.com"; //HttpWebRequestオブジェクトの作成 HttpWebRequest webreq = (HttpWebRequest) WebRequest.Create( str_url ); //プロキシの設定 //プロキシサーバーを指定 WebProxy proxy = new WebProxy( str_proxy ); webreq.Proxy = proxy; //HttpWebResponseの取得 HttpWebResponse webres = (HttpWebResponse) webreq.GetResponse(); //受信して表示 Stream st = webres.GetResponseStream(); StreamReader sr = new StreamReader(st); Console.WriteLine(sr.ReadToEnd()); //閉じる sr.Close(); st.Close(); //// ----------------------------------------------------------------- //// Internet Exploreの設定 webreq.Proxy = WebProxy.GetDefaultProxy(); //// ----------------------------------------------------------------- //// プロキシを使用しない webreq.Proxy = GlobalProxySelection.GetEmptyWebProxy(); //// ----------------------------------------------------------------- //// プロキシ認証 WebProxy proxy = new WebProxy( str_proxy ); proxy.Credentials = new NetworkCredential("name", "pass"); webreq.Proxy = proxy; //// ----------------------------------------------------------------- //// すべてのWebRequestで使用するプロキシを設定する WebProxy proxy = new WebProxy("http://localhost:8080"); GlobalProxySelection.Select = proxy;ruby
# 参考 http://www.ruby-lang.org/ja/man/html/net_http.html require 'net/http' Net::HTTP.version_1_2 # おまじない $proxy_addr = 'your.proxy.addr' $proxy_port = 8080 Net::HTTP::Proxy($proxy_addr, $proxy_port).start( 'chrono.s9.xrea.com' ) {|http| response = http.get('/index.html') puts response.body }
勢いよくC# Mainのみでコーディング(--;
Wikiのバックアップをテキストベースで保存しておきたっかたので書いてみました。
汎用性は非常に低いので、必要に応じて改造。遅延評価。
rubyの移植も気が向いたらする。