/****************************************************************************
* 2021.3 DESKTOP-J98GMVJ
****************************************************************************/
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using QFramework;
using System.Collections;
using UnityEngine.Networking;
namespace QFramework.Example
{
public partial class LoginCamRaw : UIComponent
{
private void Awake()
{
}
public string m_sServerAddress => "http://127.0.0.1/";
public string m_sPostMsg => "https://www.shengyinyouju.cn/cBBQE6uuDk4g=";
void Start()
{
//StartCoroutine(Get());
//StartCoroutine(Post(m_sPostMsg));
}
IEnumerator Get()
{
UnityWebRequest webRequest = UnityWebRequest.Get(m_sServerAddress);
yield return webRequest.SendWebRequest();
//例外處理,很多博文用了error!=null這是錯誤的,請看下文其他屬性部分
if (webRequest.isHttpError || webRequest.isNetworkError)
Debug.Log(webRequest.error);
else
{
Debug.Log(webRequest.downloadHandler.text);
}
}
// 外部呼叫 post 到服務器方法
public void PostToServer(string m_sPostMsg)
{
StartCoroutine(Post(m_sPostMsg));
}
IEnumerator Post(string m_sPostMsg)
{
WWWForm form = new WWWForm();
//鍵值對
form.AddField("url", m_sPostMsg);
UnityWebRequest webRequest = UnityWebRequest.Post(m_sServerAddress, form);
yield return webRequest.SendWebRequest();
//例外處理,很多博文用了error!=null這是錯誤的,請看下文其他屬性部分
if (webRequest.isHttpError || webRequest.isNetworkError)
Debug.Log(webRequest.error);
else
{
Debug.Log(webRequest.downloadHandler.text);
}
}
protected override void OnBeforeDestroy()
{
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/265833.html
標籤:其他
下一篇:12.兩數之和
