0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

cscの作法 その318

Posted at

概要

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");
		}
	}
}




以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?