Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Net;
- using UnityEngine;
- public class LoadData
- {
- public string data;
- HttpWebRequest webRequest;
- public LoadData(string url)
- {
- try
- {
- webRequest = (HttpWebRequest)WebRequest.Create(url);
- webRequest.BeginGetResponse(new AsyncCallback(FinishWebRequest), webRequest);
- }
- catch (WebException w)
- {
- Debug.Log("WWW Request Error : " + w.Message.ToString());
- }
- catch (Exception e)
- {
- Debug.Log("Unknown Request Error : " + e.Message.ToString());
- }
- }
- private void FinishWebRequest(IAsyncResult result)
- {
- try
- {
- HttpWebResponse response = (result.AsyncState as HttpWebRequest).EndGetResponse(result) as HttpWebResponse;
- Stream dataStream = response.GetResponseStream();
- StreamReader reader = new StreamReader(dataStream);
- data = reader.ReadToEnd();
- }
- catch (WebException w)
- {
- Debug.Log("WWW Response Error : " + w.Message.ToString());
- }
- catch (Exception e)
- {
- Debug.Log("Unknown Response Error : " + e.Message.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement