Skip to content

Instantly share code, notes, and snippets.

@nakamura001
Created June 27, 2017 10:13
Show Gist options
  • Save nakamura001/65d90c1354a1874f7287257b488a36d9 to your computer and use it in GitHub Desktop.
Save nakamura001/65d90c1354a1874f7287257b488a36d9 to your computer and use it in GitHub Desktop.
HttpWebRequestのサンプル
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