Phonegap 使用 Web 服务 PHP

Phonegap Consuming Web Service PHP

下一个问题是尝试使用 Web 服务。我尝试使用插件和纯 xml 但结果仍然是 "NULL".

代码是这样的。

function soap(imei,clave)
    {

    var divToBeWorkedOn = "#res";
    var webServiceURL = '';

    var parameters = '<?xml version="1.0" encoding="utf-8"?> \
    <soap:Envelope xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance " xmlns:xsd=" http://www.w3.org/2001/XMLSchema " xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/"> \
      <soap:Body> \
        <registra_imei> \
          <request> \
            <imei>'+imei+'</imei> \
            <clave>'+clave+'</clave> \
          </request> \
        </registra_imei> \
      </soap:Body> \
    </soap:Envelope>';

    $.ajax({
        type: "Post",
        url: webServiceURL,
        data: parameters,
        contentType: "text/xml; charset=\"utf-8\"",
        dataType: "xml",
        success: function(msg) {    
            alert("funciono "+msg);
        },
        error: function(e){
            alert("error");              
        }
    });
}

Web 服务是一个简单的 SOAP PHP。只是我需要发送变量,然后得到一个代码(1、2 或 3)的响应。

活动"registra_imei"的要求是:

Name: registra_imei
Binding: SOAPBinding
Endpoint: 
SoapAction: urn:soapwsdl#registra_imei
Style: rpc
Input:
  use: encoded
  namespace: urn:soapwsdl
  encodingStyle: http://schemas.xmlsoap.org/soap/encoding/
  message: registra_imeiRequest
  parts:
    imei: xsd:string
    clave: xsd:string
Output:
  use: encoded
  namespace: urn:soapwsdl
  encodingStyle: http://schemas.xmlsoap.org/soap/encoding/
  message: registra_imeiResponse
  parts:
    return: xsd:int
Namespace: urn:soapwsdl
Transport: http://schemas.xmlsoap.org/soap/http
Documentation: Registra imei

我的评论太长了post进入评论区

所以,我使用 SoapUI 模拟了对您 WSDL 的呼叫,我得到了 RAW 响应:

HTTP/1.1 200 OK
Date: Tue, 14 Apr 2015 19:44:24 GMT
Server: LiteSpeed
X-Powered-By: PHP/5.4.39
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Set-Cookie: PHPSESSID=870fgce5tm1ep8get75066i491; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Content-Length: 0

这是 SOAP 请求:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:soapwsdl">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:registra_imei soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <imei xsi:type="xsd:string">65656565</imei>
         <clave xsi:type="xsd:string">123</clave>
      </urn:registra_imei>
   </soapenv:Body>
</soapenv:Envelope>

RAW 请求:

POST http://soap.movilaccesscloud.cl/serversoap.php/ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:soapwsdl#registra_imei"
Content-Length: 508
Host: soap.movilaccesscloud.cl
Proxy-Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

显然,错误出在您的网络服务后端。检查您的 PHP 代码,如果可能请分享部分代码。

我再说一遍,我的本意是将评论放在适当的区域,但如您所见,它太长了。

:)