Created
June 27, 2017 10:12
-
-
Save nakamura001/587a7230c27921f83f1dd93cffdbe360 to your computer and use it in GitHub Desktop.
WebClientのサンプル
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(DigiCert) | |
const string uri3 = "https://www.digicert.com/"; // SSL(DigiCert) | |
//const string uri3 = "https://www.verisign.com/"; // SSL(VeriSign) | |
string addMsg = ""; | |
void Download(string uri) { | |
InfoInputField.text = string.Format("URI:{0}\n", uri); | |
WebClient client = new WebClient(); | |
client.DownloadFileAsync (new Uri(uri), Application.persistentDataPath + "/test"); | |
client.DownloadFileCompleted += DLComplete; | |
} | |
void DLComplete(object sender, AsyncCompletedEventArgs e) { | |
if (e.Error == null) { | |
addMsg += "DL Success!!\n"; | |
} else { | |
addMsg += string.Format("Error: {0}\n", e.Error); | |
} | |
addMsg += sender.ToString (); | |
WebClient client = sender as WebClient; | |
client.DownloadFileCompleted -= DLComplete; | |
} | |
void Update() { | |
if (!string.IsNullOrEmpty (addMsg)) { | |
InfoInputField.text += addMsg; | |
addMsg = ""; | |
} | |
} | |
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