gpt4 book ai didi

php - 使用 Android WebService 客户端和 PHP 服务器传递参数时出现问题

转载 作者:行者123 更新时间:2023-11-30 04:41:24 26 4
gpt4 key购买 nike

我有以下调用 PHP 网络服务的代码。代码连接到服务,但是参数没有传好。该方法仅返回参数,对于以下代码,它返回“mm”(基本上它返回第一个参数的第一个字母两次)。

    String SOAP_ACTION = "urn:server#userAuth"; 
String METHOD_NAME = "userAuth";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

PropertyInfo p1 = new PropertyInfo();
p1.type = PropertyInfo.STRING_CLASS;
p1.setName("usr");
p1.setValue("myuser");
p1.setNamespace(NAMESPACE);
request.addProperty(p1);

PropertyInfo p2 = new PropertyInfo();
p2.type = PropertyInfo.STRING_CLASS;
p2.setName("pass");
p2.setValue("xxxxxxxxxxx");
p2.setNamespace(NAMESPACE);
request.addProperty(p2);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);

Object result = (Object)envelope.getResponse();
return result.toString();

这是 php 服务器代码...

$server = new nusoap_server;
$server->configureWSDL('server', 'urn:server');
$server->wsdl->schemaTargetNamespace = 'urn:server';
$server->register('userAuth',
array('usr' => 'xsd:string', 'pass' => 'xsd:string'),
array('return' => 'xsd:string'),
'urn:server',
'urn:server#userAuth');

function userAuth($value){

$a=$value['usr'].$value['pass'];

return $a;
}

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';

$server->service($HTTP_RAW_POST_DATA);

最佳答案

好的,所以我最终通过在请求的 SoapObject 调用的 SoapObject 女巫的另一个实例中添加参数使其工作。最终代码是:

String SOAP_ACTION = "userAuth"; String METHOD_NAME = "userAuth";

    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

SoapObject parameters = new SoapObject(NAMESPACE, METHOD_NAME);
parameters.addProperty("usr", "myuser");
parameters.addProperty("pass", "xxxxxxxxxxxxxxx");

Request.addProperty(METHOD_NAME, parameters);



SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.setOutputSoapObject(Request);


HttpTransportSE androidHttpTransportSE = new HttpTransportSE(URL);
androidHttpTransportSE.call(SOAP_ACTION, soapEnvelope);


Object result = (Object)soapEnvelope.getResponse();
return result.toString();

关于php - 使用 Android WebService 客户端和 PHP 服务器传递参数时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5931277/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com