-
unity本地缓存
WWW.LoadFromCacheOrDownload (string url,int version)
-
http协议
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
using UnityEngine;
using System.Collections;
using System.IO;
using System.Net;
public class HttpTest : MonoBehaviour {
void Start () {
Stream outStream = File.Create(Application.streamingAssetsPath + "/test.html" );
HttpWebRequest request = (HttpWebRequest)WebRequest.Create( "http://yitaike.svfree.net/1.03/Animations/888.html" );
WebResponse response = request.GetResponse();
Stream inStream = response.GetResponseStream();
int bufferSize = 1024;
int readCount;
byte [] buffer = new byte [bufferSize];
readCount = inStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outStream.Write(buffer, 0, readCount);
readCount = inStream.Read(buffer, 0, bufferSize);
}
outStream.Close();
inStream.Close();
response.Close();
}
}
|
-
ftp协议
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
using UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.Net;
public class FtpTest : MonoBehaviour {
void Start () {
FileStream outputStream = new FileStream(Application.streamingAssetsPath + "/test.html" , FileMode.Create);
FtpWebRequest reqFTP = FtpWebRequest.Create( "" ) as FtpWebRequest;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true ;
reqFTP.Credentials = new NetworkCredential( "yitaike" , "dxc1314" );
FtpWebResponse response = reqFTP.GetResponse() as FtpWebResponse;
Stream ftpStream = response.GetResponseStream();
int bufferSize = 1024;
int readCount;
byte [] buffer = new byte [bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
response.Close();
}
}
|
-
unity www类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
using UnityEngine;
using System.Collections;
using System.IO;
public class WWWTest : MonoBehaviour {
IEnumerator Start () {
Stream outStream = File.Create(Application.streamingAssetsPath + "/test.html" );
WWW www = new WWW( "http://yitaike.svfree.net/1.03/Animations/888.html" );
yield return www;
byte [] buffer = www.bytes;
outStream.Write(buffer, 0, buffer.Length);
outStream.Close();
}
}
|
本文转蓬莱仙羽51CTO博客,原文链接:http://blog.51cto.com/dingxiaowei/1366124
,如需转载请自行联系原作者