using UnityEngine;
using System;
using System.Collections;
using System.Net;
using System.Text;
using System.Web;
public class GainToken : MonoBehaviour {
// Use this for initialization
void Start () {
}
public string content;
private string GetToken()
{
string xml = "............";//提供的XML/Json數(shù)據(jù)
try
{
byte[] data = Encoding.Default.GetBytes(xml);
string url = "..........";//提供獲取Token值的服務(wù)地址(很重要)
//如果不了解HttpWebRequest類,進入網(wǎng)址https://msdn.microsoft.com/zh-cn/library/system.net.httpwebresponse.aspx查詢
HttpWebRequest requst = (HttpWebRequest)WebRequest.Create(url);//獲取
requst.Method = "POST";//請求服務(wù)的方式
System.IO.Stream sm = requst.GetRequestStream();//Web請求
sm.Write(data, 0, data.Length);//XML數(shù)據(jù)
sm.Close();
HttpWebResponse response = (HttpWebResponse)requst.GetResponse();//響應(yīng)WebResponse從互聯(lián)網(wǎng)上的資源。
System.IO.Stream streamResponse = response.GetResponseStream();
//獲取到的Token值
System.IO.StreamReader streamRead = new System.IO.StreamReader(streamResponse, Encoding.UTF8);
Char[] readBuff = new Char[256];//字節(jié)數(shù)
int count = streamRead.Read(readBuff, 0, 256);
//轉(zhuǎn)換Token值為string形式
while (count > 0)
{
string outputData = new string(readBuff, 0, count);
content += outputData;
count = streamRead.Read(readBuff, 0, 256);
}
response.Close();//關(guān)閉Token值請求(一定要關(guān)閉,要不然會程序會死掉)
}
catch (System.Exception ex)
{
ex.ToString();
}
return content;
}
接下來,通過獲取的token值,得到URL =“http://" + ip:port + "..." + token +"....";
通過WWW類和協(xié)程獲取服務(wù)器上的數(shù)據(jù),解析。。。。。。
下面的東西就不說了,很簡單的!!
補充一個知識:獲取下來的字符串有些是多余的,我們可以將多余的摘掉,
public static string GetTokenXML(string str, string startStar, string endStr)
{
int start = str.IndexOf(startStar);
int end = str.IndexOf(endStr);
int leng = end - (start + startStar.Length);
if (start == -1)
{
return "";
}
else if (end == -1)
{
return "";
}
else
{
return str.Substring(start + startStar.Length, leng);
}
}

阿壩州網(wǎng)站制作公司哪家好,找
創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項目制作,到程序開發(fā),運營維護。
創(chuàng)新互聯(lián)自2013年起到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選
創(chuàng)新互聯(lián)。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
分享文章:Unity中Token的應(yīng)用-創(chuàng)新互聯(lián)
當(dāng)前URL:http://www.chinadenli.net/article0/deegio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、電子商務(wù)、ChatGPT、域名注冊、標簽優(yōu)化、商城網(wǎng)站
廣告
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源:
創(chuàng)新互聯(lián)