gpt4 book ai didi

php - UnityWebRequest POST 到 PHP 不起作用

转载 作者:可可西里 更新时间:2023-11-01 00:28:55 24 4
gpt4 key购买 nike

我使用 WWWForm 文档:https://docs.unity3d.com/Manual/UnityWebRequest-SendingForm.html

C#:

void Start() {
StartCoroutine(Upload());
}

IEnumerator Upload(){
yield return Upload1();
yield return Upload2();
}

IEnumerator Upload1() {
List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
formData.Add( new MultipartFormDataSection("field1=foo&field2=bar") );
//formData.Add( new MultipartFormFileSection("my file data", "myfile.txt") );

UnityWebRequest www = UnityWebRequest.Post(url, formData);
yield return www.SendWebRequest();

if(www.isNetworkError || www.isHttpError) {
Debug.Log(www.error);
}
else {
Debug.Log("Form upload complete!");
Debug.Log( "MULTIPART: " + www.downloadHandler.text );
}
}

IEnumerator Upload2() {
WWWForm form = new WWWForm();
form.AddField("myField", "myData");

UnityWebRequest www = UnityWebRequest.Post(url, form);
yield return www.SendWebRequest();

if(www.isNetworkError || www.isHttpError) {
Debug.Log(www.error);
}
else {
Debug.Log("Form upload complete!");
Debug.Log( "WWWForm: " + www.downloadHandler.text );
}
}

PHP:

<?php 

echo "POST: ";
print_r( $_POST );
var_dump( $_POST );

echo "GET: ";
print_r( $_GET );
var_dump( $_GET );

?>

响应(MULTIPART 和 WWWForm):

POST: Array
(
)
array(0) {
}
GET: Array
(
)
array(0) {
}

$_POST 是空的...(这是我的问题)

使用 Unity 2017.3。

我之前使用过 UnityWebRequest.Send (Unity 5.6),它对我一直有效,直到它变得过时。

谢谢。

最佳答案

这似乎对我有用,希望对您有所帮助。

UnityWebRequest www = UnityWebRequest.Post(url, formData);

www.chunkedTransfer = false;////ADD THIS LINE

yield return www.SendWebRequest();

关于php - UnityWebRequest POST 到 PHP 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48627680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com