简体   繁体   English

如何在PhoneGap中使用Magento API Soap Web服务

[英]How to use Magento API Soap Web services in PhoneGap

Am using PhoneGap for iOS development. 我正在使用PhoneGap进行iOS开发。 Am trying to call Magento API With the SOAP Web services in PhoneGap. 我正在尝试使用 PhoneGap中的SOAP Web服务调用Magento API My scenario is i want to send the username and apikey to the Webservice. 我的情况是我想将用户名和apikey发送到Webservice。 Since its a client based with the help of jQuery-Ajax and javascript i tried to send the data to web service but got failed. 由于它是基于jQuery-Ajax和javascript的客户端,因此我尝试将数据发送到Web服务,但失败了。

When i tried with Jquery-Ajax i got an XML parsing error states '0' as error message(Cros Domain problem). 当我尝试使用Jquery-Ajax时,我得到了XML解析错误状态“ 0”作为错误消息(跨域问题)。 In Javascript i can get the response correctly but dont know how to send the username and apikey to the web service, Below is the script code i used, 在Javascript中,我可以正确获得响应,但不知道如何将用户名和apikey发送到Web服务,以下是我使用的脚本代码,

<script type="text/javascript">
    // Create the XHR object.

  function createCORSRequest(method, url) {
    var xhr = new XMLHttpRequest();
    if ("withCredentials" in xhr) {
       // XHR for Chrome/Firefox/Opera/Safari.
       xhr.open(method, url, true);
    } else if (typeof XDomainRequest != "undefined") {
      // XDomainRequest for IE.
         xhr = new XDomainRequest();
         xhr.open(method, url);
      } else {
     // CORS not supported.
        xhr = null;
   }return xhr;

// Make the actual CORS request.

function makeCorsRequest() {
   // All HTML5 Rocks properties support CORS.
   var url = 'my WSDL link for magento api';
   var xhr = createCORSRequest('GET', url);
   if (!xhr) {
      alert('CORS not supported');
   return;}
   // Response handlers.
   xhr.onload = function() {
   var text = xhr.responseText;
      alert('Response from CORS request to ' + url);
   };
   xhr.onerror = function() {
      alert('Woops, there was an error making the request.');
   };
  xhr.send();
}
</script>

Here i don't know how to send the username and apikey to this Soap Web service. 在这里,我不知道如何将用户名和apikey发送到此Soap Web服务。

Can anyone suggest me 谁能建议我

  • how to send the username and apikey to the soap web service? 如何将用户名和apikey发送到soap Web服务?
  • Is there any alternative way to send data to soap web service using Client side programming? 是否有使用客户端编程将数据发送到Soap Web服务的其他方法?

I think you have no need to avoid the cross-domain problem of jquery. 我认为您无需避免jquery的跨域问题。

1.A simple 'jsonp' will help you solve your question. 1.一个简单的“ jsonp”将帮助您解决问题。 2.You may modify the head of response in server-side. 2.您可以在服务器端修改响应头。 Please refer to my c# code below: 请参考以下我的C#代码:

HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM