我在 php 中有一个肥皂网络服务,我试图从 Objective-C 中使用它,但我没有得到任何响应
请求正常吗?网络服务似乎工作正常..
这是我在 php 中的代码
<?php
require_once('lib/nusoap.php'); //include required class for build nnusoap web service server
// Create server object
$server = new soap_server();
// configure WSDL
$server->configureWSDL('Upload File', 'urn:uploadwsdl');
// Register the method to expose
$server->register('cadastraUsuario');
// Define the method as a PHP function
function cadastraUsuario($_name, $_surname, $_location, $_email, $_password, $_gender, $_foto, $_tipo, $_dateLogin) {
echo "tetdta";
if($_name and $_surname)
{
$name = strip_tags(trim(htmlentities($_name)));
$surname = strip_tags(trim(htmlentities($_surname)));
$location = strip_tags(trim(htmlentities($_location)));
$email = strip_tags(trim(htmlentities($_email)));
$password = strip_tags(trim(htmlentities($_password)));
$gender = strip_tags(trim(htmlentities($_gender)));
$tipo = strip_tags(trim(htmlentities($_tipo)));
$_foto = $_foto;
//Consulta o email para ver se ja esta cadastrado
$sql_consulta = "select * from `cdusers` where email = '".$email."'";
$result_consulta = mysql_query($sql_consulta);
$row = mysql_num_rows($result_consulta);
header('Content-type: text/xml');
if($row > 0)
{
print'
<resultado>
<mensagem_cadastro>Este e-mail ja esta cadastrado!</mensagem_cadastro>
</resultado>
';
}
else
{
$sql = "INSERT INTO `CDUsers` (`name`, `surname`, `location`, `email`, `password`, `gender`, `foto`, `tipo`, `dateLogin`)
VALUES ('$name', '$surname', '$location', '$email', '$password', '$gender', '$foto', '$tipo', '')";
$result = mysql_query($sql);
//Se a execucao no banco estiver ok ou nao
if($result)
{
print '
<resultado>
<mensagem_cadastro>Usuário Cadastrado com sucesso!</mensagem_cadastro>
</resultado>
';
}
else
print '
<resultado>
<mensagem_cadastro>Erro ao cadastrar o ususario!</mensagem_cadastro>
</resultado>
';
}
}
else
{
echo "nao entrou na condição";
}
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
这里是我在 Objective-C 中的代码
NSString *soapMessage = [NSString stringWithFormat:@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"; xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"; xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"; xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"; SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">";
"<SOAP-ENV:Body>\n"
"<cadastraUsuarioRequest>"
"<name>%@</name>"
"<surname>%@</surname>"
"<location>%@</location>"
"<email>%@</email>"
"<password>%@</password>"
"<gender>%@</gender>"
"<foto>%@</foto>"
"<tipo>m</tipo>"
"<dateLogin></dateLogin>"
"</cadastraUsuarioRequest>"
"</SOAP-ENV:Body>"
"</SOAP-ENV:Envelope>",txtName.text, txtSurName.text, txtLocation.text, txtEmail.text, txtPassword.text,gender,foto];
NSLog(soapMessage);
NSString *enderecoWS = @"http://www.url.it/cms/soap/server.php";
NSURL *url = [NSURL URLWithString:enderecoWS];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://www.url.it/cms/soap/server.php/cadastraUsuario"; forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
if(!webData)
webData = [[NSMutableData data] retain];
}
else
{
//NSLog(@"theConnection is NULL");
}
}
来自网络服务详细信息的方法:
关
名称:cadastraUsuario 绑定:WebServiceBinding 端点:
http://www.url.it/cms/soap/server.php SoapAction:
http://www.url.it/cms/soap/server.php/cadastraUsuario 风格:rpc
输入:使用:编码命名空间:encodingStyle:
http://schemas.xmlsoap.org/soap/encoding/ 消息:
cadastraUsuarioRequest 部分:输出:使用:编码命名空间:
encodingStyle:http://schemas.xmlsoap.org/soap/encoding/ 消息:
cadastraUsuarioResponse 部分:命名空间:传输: