java–Android KSOAP2请求PHP SOAP服务器

java–Android KSOAP2请求PHP SOAP服务器,第1张

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

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

PHP

<?PHPclass 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());    }}

解决方法:

您的URL应该是soap端点,即http://www.domain.cz/server/server.PHP

您的SOAP_ACTION应包含方法名称,即http://www.domain.cz/server/server.PHP/login

总结

以上是内存溢出为你收集整理的java – Android KSOAP2请求PHP SOAP服务器全部内容,希望文章能够帮你解决java – Android KSOAP2请求PHP SOAP服务器所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1117683.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存