Bro*_*per 2 response unity-game-engine web
如何获得Unity Web请求的响应主体?
我可以获得响应头但是不清楚在哪里找到响应主体.
[编辑]
从UnityWebRequest上的Unity文档以及DownloadHandler,响应正文数据可以看作是原始字节或文本,但由于此时此文档中没有示例,下面的答案应该显示打印出响应正文的基本用法.
[编辑]
正如程序员所说,可以在Unity 5.4 Legacy Docs中找到示例.
Bro*_*per 11
找到答案:它在于 UnityWebRequest.downloadHandler
下面是如何打印的例子都在标题和正文:
string url = "https://someurl.com";
public void SendPost()
{
StartCoroutine(SendPostCoroutine());
}
IEnumerator SendPostCoroutine()
{
WWWForm form = new WWWForm();
form.AddField("valueOne", "some stuff");
using (UnityWebRequest www = UnityWebRequest.Post(url, form))
{
yield return www.Send();
if (www.isError)
{
Debug.Log(www.error);
}
else
{
Debug.Log("POST successful!");
StringBuilder sb = new StringBuilder();
foreach (System.Collections.Generic.KeyValuePair<string, string> dict in www.GetResponseHeaders())
{
sb.Append(dict.Key).Append(": \t[").Append(dict.Value).Append("]\n");
}
// Print Headers
Debug.Log(sb.ToString());
// Print Body
Debug.Log(www.downloadHandler.text);
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9648 次 |
最近记录: |