Created
June 27, 2017 10:13
-
-
Save nakamura001/65d90c1354a1874f7287257b488a36d9 to your computer and use it in GitHub Desktop.
HttpWebRequestのサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
using System.IO; | |
using System.Net; | |
using System.Text; | |
using System; | |
using System.Collections; | |
using System.ComponentModel; | |
public class Test : MonoBehaviour { | |
public InputField InfoInputField; | |
const string uri1 = "http://d.hatena.ne.jp/nakamura001/"; // 非SSL | |
const string uri2 = "https://unity3d.com/jp/legal/privacy-policy"; // SSL(DigiCart) | |
const string uri3 = "https://www.verisign.com/"; // SSL(VeriSign) | |
void Download(string uri) { | |
string info = string.Format("URI:{0}\n", uri); | |
WebRequest request = HttpWebRequest.Create(uri); | |
request.Method = "GET"; | |
WebResponse resp = null; | |
try { | |
resp = request.GetResponse(); | |
} catch(Exception e) { | |
resp = null; | |
info += "exception:\n" + e.ToString (); | |
} | |
if (resp != null) { | |
Stream st = resp.GetResponseStream(); | |
StreamReader sr = new StreamReader(st, Encoding.GetEncoding("UTF-8")); | |
info += sr.ReadToEnd(); | |
sr.Close(); | |
st.Close(); | |
} | |
InfoInputField.text = info; | |
} | |
public void Test1() { | |
Download (uri1); | |
} | |
public void Test2() { | |
Download (uri2); | |
} | |
public void Test3() { | |
Download (uri3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment