Created
January 22, 2013 05:38
-
-
Save nakamura001/4592388 to your computer and use it in GitHub Desktop.
UnityでHttpWebRequestを使う
This file contains hidden or 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 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