【发布时间】:2018-04-04 15:22:01
【问题描述】:
我想要 Django 和 Unity 之间的图像请求。所以,我想使用 UnityWebRequest 将图像数据发送到 Json 类型。
下面的源代码是Unity C#代码。
public void onClickSendButton(){
coroutine = ServerThrows();
StartCoroutine(coroutine);
}
IEnumerator ServerThrows()
{
string imageAsJson = File.ReadAllText(imagePath);
byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(imageAsJson);
UnityWebRequest www = new UnityWebRequest(url, "POST");
www.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw);
www.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
www.chunkedTransfer = false;
www.SetRequestHeader("Content-Type","application/json");
yield return www.SendWebRequest();
if(www.isNetworkError||www.isHttpError){
Debug.Log(www.error);
}
else
{
GetResponse(www);
}
}
这是 Django 服务器代码:
def fromunity(request):
data = json.loads(request.body.decode('utf-8'))
print(data)
print(request.content_type)
return HttpResponse()
在 Unity 中,当我通过 onClickSendButton 发送请求时,Django Server 显示以下结果: enter image description here
(json.decoder.JSONDecodeError: 期望值: line 1 column 1 (char 0))
根据上面的 Django Server 结果,我该怎么办?
【问题讨论】:
标签: json django unity3d request