hi all,
we're using file_get_contents to communicate with a web service, which creates users and if succeeds it returns a JSON object with the details of the new created user. the code below shows how we do it, the user is successfully created, meaning we can see it from the back-end, however, we just can't get the JSON response, it returns nothing.
public function register(){
$username = "testing";
$email = "[email protected]";
$password = "testpsd";
$userData = '{"$xmlns": {"pluser": "http://xml.webservice.com/auth/data/User"},'
.'"pluser$userName": "'.$username.'",'
.'"pluser$password": "'.$password.'",'
.'"pluser$fullName": "fullname",'
.'"pluser$email": "'.$email.'"}';
$url = 'https://webservice.com?form=json';
$cparams = array('http' => array('method' => 'POST','ignore_errors' => true));
$cparams['http']['content'] = $userData;
$cparams['http']['request_fulluri'] = true;
$cparams['http']['header'] = 'Content-type: application/json';
$context = stream_context_create($cparams);
$fp = @file_get_contents($url,false,$context);$res = stream_get_contents($fp);
print_r($res);
}
at first we thought the web service was supposed to return nothing, so we tested against it in c# which worked perfectly fine, meaning we got the create response of something like {"stutas":"successful","userCreated":"true"} here is the c# code:
String url = "https://webservice.com?form=json";
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(url);
req.Method = "POST";
string strRequest = "exactly the same json string";
req.ContentLength = strRequest.Length;
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
while (!streamIn.EndOfStream)
Console.WriteLine(streamIn.ReadToEnd());
streamIn.Close();
Console.ReadKey();}
is there anything missing or misconfigured in the php code?