小编Ser*_*gey的帖子

UnityWebRequest POST到PHP不起作用

我使用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 …
Run Code Online (Sandbox Code Playgroud)

php post webrequest unity-game-engine

3
推荐指数
1
解决办法
4503
查看次数

标签 统计

php ×1

post ×1

unity-game-engine ×1

webrequest ×1