Last active
August 29, 2015 14:00
-
-
Save snaka/11278774 to your computer and use it in GitHub Desktop.
HTTPでWebサーバからレスポンスを受け取る ref: http://qiita.com/snaka/items/4e384a7f9ce80b98b71b
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.Collections; | |
| public class Main : MonoBehaviour { | |
| public string url = "http://www.google.com"; | |
| public string output = "(ここに結果を表示)"; | |
| private GetViaHttp http; | |
| void Start() { | |
| http = GetComponent<GetViaHttp>(); | |
| } | |
| void OnGUI() { | |
| // Button | |
| if(GUI.Button(new Rect(30, 30, 100, 30), "GET via HTTP")) { | |
| Debug.Log("GET!!!"); | |
| StartCoroutine("GetUrl"); | |
| } | |
| // TextArea for Output | |
| GUI.TextArea(new Rect(30, 70, 800, 600), output); | |
| } | |
| private IEnumerator GetUrl() { | |
| Debug.Log("Start2"); | |
| WWW www = new WWW(url); | |
| yield return www; | |
| Debug.Log(www.text); | |
| output = www.text; | |
| } | |
| } |
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.Collections; | |
| public class Main : MonoBehaviour { | |
| public string url = "http://www.google.com"; | |
| public string output = "(ここに結果を表示)"; | |
| private GetViaHttp http; | |
| void Start() { | |
| http = GetComponent<GetViaHttp>(); | |
| } | |
| void OnGUI() { | |
| // Button | |
| if(GUI.Button(new Rect(30, 30, 100, 30), "GET via HTTP")) { | |
| Debug.Log("GET!!!"); | |
| StartCoroutine("GetUrl"); | |
| } | |
| // TextArea for Output | |
| GUI.TextArea(new Rect(30, 70, 800, 600), output); | |
| } | |
| private IEnumerator GetUrl() { | |
| Debug.Log("Start2"); | |
| WWW www = new WWW(url); | |
| yield return www; | |
| Debug.Log(www.text); | |
| output = www.text; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment