P
P
ProgramDevel2020-09-18 08:37:24
Unity
ProgramDevel, 2020-09-18 08:37:24

Why am I getting an empty string from the server?

I have a C# code and a PHP server

C# code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Avtorizaion : MonoBehaviour
{


    private void Start()
    {
    	StartCoroutine(Send());
    }

    private IEnumerator Send(){
    	WWWForm form = new WWWForm();
    	form.AddField("W", "Привет");
    	WWW www = new WWW("Тут ссылка на мой сервер, но я решил её убрать в вопросе", form);
    	yield return www;
    	if (www.error != null)
    	{
    		Debug.Log("Ошибка: " + www.error);
    		yield break;
    	}
    	Debug.Log("Сервер ответил: " + www.text);
    }	
}


php server
<?php
if (!isset($_POST['W'])) exit;
if ($_POST['W'] == "Привет") echo 'Ку';
?>


And the answer from the server gives me an empty string!
What to do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2020-09-18
@freeExec

What to do?

You need to debug your code. Save the incoming request on the server and stick why you came ∩╗┐╨ƒ╤Ç╨╕╨▓╨╡╤éinsteadПривет

V
Vitaliy Antipin, 2020-09-18
@Stelette

To begin with, I would recommend using Unitywebrequest. And for example, you can transfer data by passing parameters to the link. Example: https://my-server.net/print.php?W="Hi "

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question