Skip to content

Instantly share code, notes, and snippets.

@nakamura001
Created January 22, 2013 05:38
Show Gist options
  • Save nakamura001/4592388 to your computer and use it in GitHub Desktop.
Save nakamura001/4592388 to your computer and use it in GitHub Desktop.
UnityでHttpWebRequestを使う
using UnityEngine;
using System.IO;
using System.Net;
using System.Text;
public class Test : MonoBehaviour {
private string txt = "";
void OnGUI () {
if (GUI.Button(new Rect(10, 10, 200, 100), "テスト")) {
WebRequest request = HttpWebRequest.Create("http://japan.unity3d.com/");
request.Method = "GET";
WebResponse resp = null;
try {
resp = request.GetResponse();
} catch {
resp = null;
}
if (resp != null) {
Stream st = resp.GetResponseStream();
StreamReader sr = new StreamReader(st, Encoding.GetEncoding("UTF-8"));
txt = sr.ReadToEnd();
sr.Close();
st.Close();
}
}
GUI.TextArea(new Rect(10, 120, Screen.width-20, 300), txt);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment