php soap android,java – Android KSOAP2请求PHP SOAP服务器

我想在我的

Android应用程序中创建一个SOAP客户端.我已经用php SOAP客户端测试了服务器,它一直在工作.但在我的Android应用程序中,我仍然得到例外.任何人都可以帮我解决错误以及如何解决这个问题?谢谢

PHP

class service

{

public function service()

{ }

public function login($nickname, $password)

{

$sql = "select nick from user

where

nick =\"$nick\"

and

pass = \"$password\"";

if (($result = $this->db->query($sql)) && ($result->num_rows == 1))

return true;

else

return false;

}

}

$server = new SoapServer(null, array(

'uri' => "urn://www.domain.cz",

'soap_version' => SOAP_1_2)

);

$server->setClass("service");

$server->handle();

?>

Android的

private static String SOAP_ACTION = "http://www.domain.cz/server/server.php";

private static String NAMESPACE = "urn://www.domain.cz";

//need fix namespace to work, final solution

// private static String NAMESPACE = "http://www.domain.cz/server/";

private static String METHOD_NAME = "login";

private static String URL = "http://www.domain.cz";

public void Connect()

{

//Initialize soap request + add parameters

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

//Use this to add parameters

request.addProperty("nick","peter");

request.addProperty("password","somepassword");

//Declare the version of the SOAP request

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);

envelope.setOutputSoapObject(request);

//Needed to make the internet call

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try {

//this is the actual part that will call the webservice

androidHttpTransport.call(SOAP_ACTION, envelope);//HERE is xmlpullparserexception after a while

} catch (Exception e) {

e.printStackTrace();

}

// Get the SoapResult from the envelope body.

SoapObject result = (SoapObject)envelope.bodyIn;

if(result != null){

TextView t = (TextView)this.findViewById(R.id.resultbox);

//Get the first property and change the label text

t.setText("SOAP response:\n\n" + result.getProperty(0).toString());

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值