Phonegap使用Web服务PHP

时间:2015-04-14 19:27:33

标签: php web-services cordova phonegap-build

下一个问题是尝试使用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

1 个答案:

答案 0 :(得分:0)

我的评论太长,无法发布到评论区域。

因此,使用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)

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

我再说一遍,我的意图是将评论放在适当的区域,但你可以看到它太长了。

:)