我有二进制流,我希望它以字节为单位。之后,我想将其下载到 SD 卡中。
我的网络服务:
POST /**********Mobile/**********.asmx HTTP/1.1
Host: ***.***.*.*
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetDocument"
<?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>
<GetDocument xmlns="http://tempuri.org/">
<DocumentID>string</DocumentID>
</GetDocument>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<GetDocumentResponse xmlns="http://tempuri.org/">
<GetDocumentResult>string</GetDocumentResult>
</GetDocumentResponse>
</soap:Body>
</soap:Envelope>
我正在尝试的是
SoapObject DocumentRequest = new SoapObject(NAMESPACE, GET_DOCUMENT_METHOD);
DocumentRequest.addProperty("DocumentID", ID);
Log.i("DocumentID", ID);
SoapSerializationEnvelope Envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
Envelope.dotNet = true;
Envelope.setOutputSoapObject(DocumentRequest);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION_GETDOCUMENT, Envelope);
SoapPrimitive DocumentResponse = (SoapPrimitive)Envelope.getResponse();
Log.i("DocumentResponse", DocumentResponse.toString());
String DocAsString = DocumentResponse.toString();
byte[] decodedString = DocAsString.getBytes();
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
ImageView DisplayDoc= (ImageView)findViewById(R.id.displayimage);
DisplayDoc.setImageBitmap(decodedByte);
}
我得到二进制流作为字符串是正确的还是我需要使用base64binary。如果是这样,请让我知道下载图像/.pdf/word 文档的正确方法。我已经完成了差异搜索,但没有用。谢谢
编辑:
SoapPrimitive DocumentResponse = (SoapPrimitive)Envelope.getResponse();
Log.i("DocumentResponse", DocumentResponse.toString());
String DocAsString = DocumentResponse.toString();
byte[] decodedString = Base64.decode(DocAsString, Base64.DEFAULT);
/*Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
ImageView DisplayDoc= (ImageView)findViewById(R.id.displayimage);
DisplayDoc.setImageBitmap(decodedByte);*/
File direct = new File(Environment.getExternalStorageDirectory() + "/Downloads");
if(!direct.exists()) {
direct.mkdir(); }
File photo=new File(Environment.getExternalStorageDirectory() + "/Downloads", ID);
if (photo.exists()) {
photo.delete(); }
try {
FileOutputStream fos=new FileOutputStream(photo.getPath());
fos.write(decodedString);
fos.close();
ContentValues values= new ContentValues();
System.out.println(values);
}
catch (java.io.IOException e)
{
Log.e("PictureDemo", "Exception in photoCallback", e);
}
}
catch(Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), " Network Exception : " + e
+ "Please check network connectivity.", Toast.LENGTH_LONG).show();
}
}
已编辑,Web 服务响应
03-19 10:58:57.797: D/dalvikvm(789): GC_FOR_ALLOC freed 57K, 4% free 6912K/7171K, paused 53ms
03-19 10:58:57.807: I/dalvikvm-heap(789): Grow heap (frag case) to 7.313MB for 488976-byte allocation
03-19 10:58:57.957: D/dalvikvm(789): GC_CONCURRENT freed 1K, 4% free 7388K/7687K, paused 4ms+14ms
03-19 10:58:58.357: D/gralloc_goldfish(789): Emulator without GPU emulation detected.
03-19 10:58:58.497: W/TextLayoutCache(789): computeValuesWithHarfbuzz -- need to force to single run
03-19 10:59:02.327: D/InputEventConsistencyVerifier(789): KeyEvent: ACTION_UP but key was not down.
03-19 10:59:02.327: D/InputEventConsistencyVerifier(789): in android.widget.EditText@41054cd8
03-19 10:59:02.327: D/InputEventConsistencyVerifier(789): 0: sent at 2335155000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=2335155, downTime=2335119, deviceId=0, source=0x101 }
03-19 10:59:04.488: I/LoginDetail(789): Username jarnail@sassypuma.comPassword admin
03-19 10:59:04.537: D/dalvikvm(789): GC_FOR_ALLOC freed 71K, 3% free 7634K/7815K, paused 40ms
03-19 10:59:04.937: I/myLogin(789): 1
03-19 10:59:05.357: D/dalvikvm(789): GC_CONCURRENT freed 360K, 7% free 7698K/8199K, paused 7ms+23ms
03-19 10:59:05.547: I/AllFolders(789): anyType{TreeData=anyType{ID=13002; FolderName=My Drive; ParentID=0; CreatedBy=1; }; TreeData=anyType{ID=13006; FolderName=Testing1; ParentID=0; CreatedBy=1; }; TreeData=anyType{ID=13007; FolderName=Testing123; ParentID=0; CreatedBy=1; }; }
03-19 10:59:05.547: I/System.out(789): 3
03-19 10:59:06.057: D/dalvikvm(789): GC_CONCURRENT freed 362K, 7% free 7761K/8263K, paused 31ms+7ms
03-19 10:59:06.217: W/TextLayoutCache(789): computeValuesWithHarfbuzz -- need to force to single run
03-19 10:59:06.627: W/IInputConnectionWrapper(789): finishComposingText on inactive InputConnection
03-19 10:59:08.307: I/FolderID(789): 13002
03-19 10:59:08.307: I/User_ID(789): 1
03-19 10:59:08.367: D/dalvikvm(789): GC_FOR_ALLOC freed 16K, 5% free 7874K/8263K, paused 45ms
03-19 10:59:08.377: I/dalvikvm-heap(789): Grow heap (frag case) to 8.036MB for 262160-byte allocation
03-19 10:59:08.417: D/dalvikvm(789): GC_FOR_ALLOC freed 3K, 6% free 8127K/8583K, paused 44ms
03-19 10:59:08.917: I/SubFolders(789): anyType{FileFolderDetails=anyType{ID=13003; Name=Doc file; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13004; Name=My Pics; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13005; Name=Testing; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13075; Name=satnam; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13080; Name=Saini; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13084; Name=Jelly; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13092; Name=pushie; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13096; Name=Jarnail_Testing; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13099; Name=amarjeet; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13101; Name=Kaam; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13103; Name=tajmehal; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13105; Name=TextArea; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13107; Name=TextArea1; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13109; Name=TextArea2; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13115; Name=TextArea3; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13121; Name=TextArea5; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13124; Name=Check Char; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13128; Name=amitestinggggg; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13132; Name=kkk; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13136; Name=hhhhhhhhhhhhhhhhhh; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13140; Name=ravitevffvvgfdcvgbgvf; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=13144; Name=DMS3.0_Title_Page; URL=anyType{}; SubjectType=Folder; }; FileFolderDetails=anyType{ID=20; Name=office.jpg; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=21; Name=Capture.PNG; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=22; Name=groups.jpg; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=23; Name=Capture1.PNG; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=99; Name=Content4Work.pdf; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=109; Name=Rohit.docx; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=115; Name=Chrysanthemum.jpg; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=123; Name=DMS_Drag_and_Drop(2).doc; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=124; Name=Tulips.jpg; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=125; Name=Jellyfish.jpg; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=126; Name=Koala.jpg; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=127; Name=Lighthouse.jpg; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=128; Name=Jellyfish.jpg; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=129; Name=Jellyfish.jpg; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=130; Name=Jellyfish.jpg; URL=InterLogicsMobile/image/Tulips.jpg; SubjectType=File; }; FileFolderDetails=anyType{ID=131; Name=Jellyfish.jpg; URL=http
03-19 10:59:08.917: I/System.out(789): 41
03-19 10:59:09.527: D/dalvikvm(789): GC_CONCURRENT freed 571K, 9% free 8012K/8711K, paused 23ms+26ms
03-19 10:59:12.787: D/dalvikvm(789): GC_FOR_ALLOC freed 11K, 5% free 8352K/8711K, paused 49ms
03-19 10:59:12.857: D/dalvikvm(789): GC_FOR_ALLOC freed 1K, 3% free 8712K/8967K, paused 50ms
03-19 10:59:12.937: D/dalvikvm(789): GC_FOR_ALLOC freed <1K, 4% free 9163K/9479K, paused 48ms
03-19 10:59:15.427: I/System.out(789): 13003
03-19 10:59:15.427: I/DocumentID(789): 13003
03-19 10:59:15.837: D/dalvikvm(789): GC_CONCURRENT freed 328K, 5% free 9581K/10055K, paused 23ms+5ms
03-19 10:59:15.867: I/DocumentResponse(789): UEsDBBQABgAIAAAAIQAJJIeCgQEAAI4FAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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