【问题标题】:How to upload file from another language like titanium ios app and java application to a c# webservice如何将文件从另一种语言(如钛 ios 应用程序和 Java 应用程序)上传到 c# web 服务
【发布时间】:2012-09-21 18:50:21
【问题描述】:

现在对我来说这是一个 grt 难题。我开发了一个使用多种语言实现的产品,例如 C# Windows 应用程序、Titanium iOS 应用程序和一个 Java 应用程序和一个朋友团队。

我正在使用一个 c# Web 服务,它采用数据类型为 byte[] 的参数。我已通过将 Windows 应用程序添加到服务参考中完成了我的工作。

我的 Titanium 团队伙伴要求我为此 Web 服务创建一些示例代码,而不是直接通过 url 使用服务引用,而是:

  • 使用soap 或http post 方法调用它。
  • 创建一个网络服务,他们可以轻松地与钛一起使用
  • 关于如何使用相同的 web 服务和钛的任何其他有用的想法

因为钛男孩现在对钛比较新鲜,所以我必须做点什么,但我也被困住了,不知道如何给他建议,所以我需要你的帮助。

【问题讨论】:

    标签: c# web-services file-upload titanium bytearray


    【解决方案1】:

    我建议您将二进制数据编码为 Base64 字符串并将其发送到您的 C# 服务。由于您使用的是 SOAP,这将是一个非常简单的解决方案。

    【讨论】:

      【解决方案2】:

      只需使用内置的 Titanium 实用程序将您的数据编码为 base64:

      // Encode your data
      var data = Titanium.Utils.base64encode(dataToSendToWebService);
      

      现在使用 HTTPClient 发送它:

      var postDataTOServer = Ti.Network.createHTTPClient({
          onload : function(e) {
               // If the service returns successfully : true, or false
               var isUserAllowed = this.responseText; 
          },
          onerror : function(e) {
              // Web service failed for some reason
              Ti.API.info(this.responseText);
              Ti.API.info('webservice failed with message : ' + e.error);
          }
      });
      
      // POST
      postDataTOServer.open('POST', 'http://yoursite.com/aspwebservice');
      
      // you may have to change the content type depending on your service
      // but this is the correct type for binary data
      postDataTOServer.setRequestHeader("Content-Type", "application/octet-stream");
      
      // This does a POST to server
      postDataTOServer.send(data);
      

      【讨论】:

        猜你喜欢
        • 2023-03-20
        • 2010-09-13
        • 2017-06-06
        • 1970-01-01
        • 1970-01-01
        • 2013-11-09
        • 2013-01-10
        • 1970-01-01
        • 2013-06-15
        相关资源
        最近更新 更多