概要
cscの作法、調べてみた。
練習問題、やってみた。
練習問題
wgetを、実装せよ。
サンプルコード
using System;
using System.IO;
using System.Net;
using System.Text;
namespace App
{
class test {
static void Wget(string url) {
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
Encoding enc = Encoding.GetEncoding("Shift_JIS");
WebRequest req = WebRequest.Create(url);
WebResponse res = req.GetResponse();
Stream st = res.GetResponseStream();
StreamReader sr = new StreamReader(st, enc);
string txt = sr.ReadToEnd();
sr.Close();
st.Close();
string name = url;
while (name.Contains("/"))
{
int index = name.IndexOf('/');
name = name.Remove(0, index + 1);
}
Console.WriteLine(name);
StreamWriter sw = new StreamWriter(name, false);
sw.Write(txt);
sw.Close();
}
static void Main() {
Wget("https://resolvenet.org/modules/contrib/webform/tests/files/sample.json");
}
}
}
以上。