Hello,
i’m trying to create a simple php HelloWorld webservice and consume it in unity 3D.
here’s my webservice script test.php
<?php
function hello() {
return "hello world";
}
try
{
$server = new SoapServer(null, array('uri' => 'http://127.0.0.1/KitchenAR/test.php'));
$server->addFunction('hello');
$server->handle();
}
catch(Exception $e)
{
echo "Exception: " . $e;
}
?>
i’ve made another php file (code is right bellow) so i can use it my localhost and everything works just fine,
<?php
try
{
$clientSOAP = new SoapClient( null,
array (
'uri' => 'http://127.0.0.1/KitchenAR/test.php',
'location' => 'http://127.0.0.1/KitchenAR/test.php',
'trace' => 1,
'exceptions' => 0
));
$ret = $clientSOAP->__call('hello', array());
echo $ret;
echo '
';
}
catch(SoapFault $f)
{
echo $f;
}
?>
moving on to unity i’ve used the WWW class, but it seems like my www.text is empty.
here’s my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Webservices : MonoBehaviour {
public GameObject text;
public string url = "http://127.0.0.1/KitchenAR/test.php";
private Text m_text;
IEnumerator Start()
{
m_text = text.GetComponent<Text>();
WWW www = new WWW(url);
yield return www;
if (www.error == null)
{
text.GetComponent<Text>().text = www.text;
Debug.Log("Sucess: " + text.GetComponent<Text>().text);
}
else
{
Debug.Log("Fail: " + www.error);
}
}
}
any idea what i’m doing wrong ?
thanks