Php 消费Web服务不会';行不通
我在php中有一个soap Web服务,我试图从objective-C中使用它,但没有得到响应 请求可以吗?Web服务显示“正常工作” 这是我用php编写的代码Php 消费Web服务不会';行不通,php,objective-c,ios4,Php,Objective C,Ios4,我在php中有一个soap Web服务,我试图从objective-C中使用它,但没有得到响应 请求可以吗?Web服务显示“正常工作” 这是我用php编写的代码 <?php require_once('lib/nusoap.php'); //include required class for build nnusoap web service server // Create server object $server = new soap_s
<?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);
?>
您的代码看起来正确,您是否实现了委托方法,例如:
NSURL *url = [NSURL URLWithString:@"http://google.co.uk"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
(void) [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
委托职能:
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(@"got response back");
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"http data: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}
检查您的Web服务HTTP头响应,它根据其实现方式而有所不同,但成功的请求应返回201。有关其他代码,请参阅
NSError *error;
NSHTTPURLResponse *response;
(void) [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"Response error: http response: %@", response.statusCode);
是的,我已经实现了…但是没有得到答案。。。在ReceiverResponse和receiveData中…请查看我的编辑您得到了什么状态码?您是否使用Mac之类的客户端测试来测试您的请求?我的意思是,问题出在webservice中
NSError *error;
NSHTTPURLResponse *response;
(void) [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"Response error: http response: %@", response.statusCode);