用于下载/上传的Android Ksoap2 web服务

用于下载/上传的Android Ksoap2 web服务,android,web-services,android-ksoap2,Android,Web Services,Android Ksoap2,我想使用ksoapweb服务编写一个程序,并从web服务下载一个文件到android手机。我必须访问web服务中的文本文件并将其下载到android手机中。有人能帮我提供教程或相应的链接吗?KSOAP只需发送请求并获得响应。在网络搜索中有很多例子,可以找到合适的例子。这里有一些例子 对于通过soapweb服务上传和下载文件,我使用以下方法 上传: 将文本文件转换为二进制字符串 将其存储到单个字符串中 通过soapweb服务发送它 范例 Uri uriString = Uri.parse(

我想使用
ksoap
web服务编写一个程序,并从web服务下载一个文件到android手机。我必须访问web服务中的文本文件并将其下载到android手机中。有人能帮我提供教程或相应的链接吗?KSOAP只需发送请求并获得响应。在网络搜索中有很多例子,可以找到合适的例子。这里有一些例子

对于通过soapweb服务上传和下载文件,我使用以下方法

上传:
  • 将文本文件转换为二进制字符串
  • 将其存储到单个字符串中
  • 通过soapweb服务发送它
  • 范例

    Uri uriString = Uri.parse(objBundle.get("").toString());
    File file = new File(uriString.getPath());
    FileInputStream objFileIS;
    objFileIS = new FileInputStream(file);
    ByteArrayOutputStream objByteArrayOS = new ByteArrayOutputStream();
    byte[] byteBufferString = new byte[1024];
    for (int readNum; (readNum = objFileIS.read(byteBufferString)) != -1;) 
    {
    objByteArrayOS.write(byteBufferString, 0, readNum);
    system.out.println("read " + readNum + " bytes,");
    }                    
    byte[] byteBinaryData = Base64.encode((objByteArrayOS.toByteArray()), Base64.DEFAULT);
    strAttachmentCoded = new String(byteBinaryData);
    
    byte[] bytes;
    strBinaryPDFString = cursorGetBinaryString.getString(0);//Index position of the binary string in table
    File createfile = new File(Environment.getExternalStorageDirectory(),"/Folder/");
    createfile.mkdirs();
    File outputFile = new File(createfile,"FileName.pdf");//creating temporary file in phone Memory
    new FileOutputStream(outputFile);
    bytes = Base64.decode(strBinaryPDFString,Base64.DEFAULT);
    File filepath = new File(Environment.getExternalStorageDirectory(),"/Folder/FileName.pdf");
    OutputStream pdffos = new FileOutputStream(filepath);
    pdffos.write(bytes);//writing the binary string into the payslip.pdf temporary file
    pdffos.flush();
    pdffos.close();
    
    下载:
  • 要求服务器端开发人员以二进制字符串格式发送文件
  • 获取响应字符串并将其转换为文件并存储在SD卡中
  • 范例

    Uri uriString = Uri.parse(objBundle.get("").toString());
    File file = new File(uriString.getPath());
    FileInputStream objFileIS;
    objFileIS = new FileInputStream(file);
    ByteArrayOutputStream objByteArrayOS = new ByteArrayOutputStream();
    byte[] byteBufferString = new byte[1024];
    for (int readNum; (readNum = objFileIS.read(byteBufferString)) != -1;) 
    {
    objByteArrayOS.write(byteBufferString, 0, readNum);
    system.out.println("read " + readNum + " bytes,");
    }                    
    byte[] byteBinaryData = Base64.encode((objByteArrayOS.toByteArray()), Base64.DEFAULT);
    strAttachmentCoded = new String(byteBinaryData);
    
    byte[] bytes;
    strBinaryPDFString = cursorGetBinaryString.getString(0);//Index position of the binary string in table
    File createfile = new File(Environment.getExternalStorageDirectory(),"/Folder/");
    createfile.mkdirs();
    File outputFile = new File(createfile,"FileName.pdf");//creating temporary file in phone Memory
    new FileOutputStream(outputFile);
    bytes = Base64.decode(strBinaryPDFString,Base64.DEFAULT);
    File filepath = new File(Environment.getExternalStorageDirectory(),"/Folder/FileName.pdf");
    OutputStream pdffos = new FileOutputStream(filepath);
    pdffos.write(bytes);//writing the binary string into the payslip.pdf temporary file
    pdffos.flush();
    pdffos.close();
    

    以上方法对我来说很有效。也许你可以找到另一个最好的方法。

    KSOAP
    就是简单地发送请求并获得响应。在网络搜索中有很多例子,可以找到合适的例子。这里有一些例子

    对于通过soapweb服务上传和下载文件,我使用以下方法

    上传:
  • 将文本文件转换为二进制字符串
  • 将其存储到单个字符串中
  • 通过soapweb服务发送它
  • 范例

    Uri uriString = Uri.parse(objBundle.get("").toString());
    File file = new File(uriString.getPath());
    FileInputStream objFileIS;
    objFileIS = new FileInputStream(file);
    ByteArrayOutputStream objByteArrayOS = new ByteArrayOutputStream();
    byte[] byteBufferString = new byte[1024];
    for (int readNum; (readNum = objFileIS.read(byteBufferString)) != -1;) 
    {
    objByteArrayOS.write(byteBufferString, 0, readNum);
    system.out.println("read " + readNum + " bytes,");
    }                    
    byte[] byteBinaryData = Base64.encode((objByteArrayOS.toByteArray()), Base64.DEFAULT);
    strAttachmentCoded = new String(byteBinaryData);
    
    byte[] bytes;
    strBinaryPDFString = cursorGetBinaryString.getString(0);//Index position of the binary string in table
    File createfile = new File(Environment.getExternalStorageDirectory(),"/Folder/");
    createfile.mkdirs();
    File outputFile = new File(createfile,"FileName.pdf");//creating temporary file in phone Memory
    new FileOutputStream(outputFile);
    bytes = Base64.decode(strBinaryPDFString,Base64.DEFAULT);
    File filepath = new File(Environment.getExternalStorageDirectory(),"/Folder/FileName.pdf");
    OutputStream pdffos = new FileOutputStream(filepath);
    pdffos.write(bytes);//writing the binary string into the payslip.pdf temporary file
    pdffos.flush();
    pdffos.close();
    
    下载:
  • 要求服务器端开发人员以二进制字符串格式发送文件
  • 获取响应字符串并将其转换为文件并存储在SD卡中
  • 范例

    Uri uriString = Uri.parse(objBundle.get("").toString());
    File file = new File(uriString.getPath());
    FileInputStream objFileIS;
    objFileIS = new FileInputStream(file);
    ByteArrayOutputStream objByteArrayOS = new ByteArrayOutputStream();
    byte[] byteBufferString = new byte[1024];
    for (int readNum; (readNum = objFileIS.read(byteBufferString)) != -1;) 
    {
    objByteArrayOS.write(byteBufferString, 0, readNum);
    system.out.println("read " + readNum + " bytes,");
    }                    
    byte[] byteBinaryData = Base64.encode((objByteArrayOS.toByteArray()), Base64.DEFAULT);
    strAttachmentCoded = new String(byteBinaryData);
    
    byte[] bytes;
    strBinaryPDFString = cursorGetBinaryString.getString(0);//Index position of the binary string in table
    File createfile = new File(Environment.getExternalStorageDirectory(),"/Folder/");
    createfile.mkdirs();
    File outputFile = new File(createfile,"FileName.pdf");//creating temporary file in phone Memory
    new FileOutputStream(outputFile);
    bytes = Base64.decode(strBinaryPDFString,Base64.DEFAULT);
    File filepath = new File(Environment.getExternalStorageDirectory(),"/Folder/FileName.pdf");
    OutputStream pdffos = new FileOutputStream(filepath);
    pdffos.write(bytes);//writing the binary string into the payslip.pdf temporary file
    pdffos.flush();
    pdffos.close();
    

    以上方法对我来说很有效。也许你能找到另一个最好的方法。

    我不知道,但我写了一个程序从web服务访问值,并做到了这一点。但我不知道下载或上传一个文件。我不知道,但我写了一个程序,从web服务访问值,并做到了这一点。但是我没有下载或上传文件的想法。安卓苹果我知道网络服务,但我想要一个上传/下载文本文件链接的例子。请在任何地方重新更新它们。Android Apple我知道web服务,但我想要一个上传/下载文本文件链接的示例。如果在任何地方可用,请重新更新。