I know it's a really asked question, and I'm writing this after checking almost every similar question already asked. In every posted question the solution was to add a name attribute to the form, but I already did it before getting the error.
So this is the problem: I'm trying to implement a basic SOAP web service that by now just prints a sentence using the name passed from the submit form. Here I add both client, server and form codes. I hope someone can help!
soapserver.php
$server = new nusoap_server;
$server->configureWSDL('server','urn:server');
$server->wsdl->schemaTargetNamespace = 'urn:server';
$server->register('register',
array('username' => 'xsd:string'), //input parameter
array('return' => 'xsd:string'), //output
'urn:server', //namespace
'urn:server#helloServer', //SOAP action
'rpc',
'encoded',
'Registrar un usuari'); //description
function register($username) {
return 'L\'usuari '.$username.' s\'ha registrat correctament!';
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
soapclient.php
$wsdl = "http://localhost/soapserver.php?wsdl";
$client = new nusoap_client($wsdl,'wsdl');
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2>' . $err;
exit();
}
if ($_POST) {
echo $_POST;
}
if (isset($_POST["user"])) {
echo $_POST["user"];
}
soapform.html
<html>
<body>
<form name="reg_form" action="soapclient.php" method="POST">
Username: <input type="text" name="user"/>
Password: <input type="password" name="password"/>
<input type="submit" name="submit" value="Sign up"/>
</form>
</body>
</html>
What I get when I submit the form is just nothing, as the isset($_POST["user"]) and isset($_POST) return false and therefore nothing happens.
I'll just post it as an answer so anybody having the same issue can find it easily.
I just solved it myself by changing $_POST by $_REQUEST even I still don't know why the other way wouldn't work...
Edit: after checking deeper into it, I've seen with Chrome that the request sent was a GET request while it should have to be a POST. So finally I've fixed it changing the action from action="soapclient.php"
to action="/soapclient.php"
and now it sent a POST and the variable $_POST had the value of the username.
Collected from the Internet
Please contact javaer1[email protected] to delete if infringement.
Comments