2017-02-03 50 views
0

當我發送一個GET請求的XML響應格式:錯誤與Azure的blob服務API

GET 











x-ms-date:Fri, 03 Feb 2017 05:50:10 GMT 
x-ms-version:2016-05-31 
/xyz/mycontainer 
comp:list 
delimeter:/ 
maxresults:1000 
prefix:image 
restyle:container 

請求成功與代碼200和消息「OK」。但是,解析響應時出現錯誤。

Error: Error while parsing XML: Content is not allowed in prolog.

但是,當我第一次取出3個字節:

while(i!=3){ 
       System.out.println(in.read()); 
       i++; 
      } 

它開始正確地解析XML。

當我在ASCII碼錶中查找這些代碼時。我發現以下特點:

'╗┐

爲什麼Azure的Blob服務REST API在XML的開始響應添加這些字符?

我的朋友說這可能是因爲這個特殊的響應頭包括傳輸編碼:在頭中分塊。 但是,我不明白他在說什麼,他自己也不確定?

Code: Simple XML Parsing code.

Response: Starting bits:

<?xml version="1.0" encoding="utf-8"?><EnumerationResults 
    > ServiceEndpoint="http://xyz.blob.core.windows.net/" 
    > ContainerName="mycontainer"><Prefix>xyz</Prefix><MaxResults>1000</MaxResults><Blobs><Blob><Name>xyz</Name> 
+0

您可以分享您得到的XML響應,以及解析該XML的代碼嗎? –

+0

看起來您並沒有閱讀完整的響應XML應該以''。 –

+0

@GauravMantri Gaurav我還沒有發佈完整的回覆。但是,謝謝我得到了答案,這很棘手,必須轉到調試器模式來閱讀完整響應頭。 –

回答

0

我得到了答案。基本上,Azure對不同的響應傳輸使用不同的傳輸編碼。通常對於大文件,它使用分塊傳輸編碼。 。

所以,如果我想使用塊傳輸編碼數據傳輸「Arjun_rocks」這將是:

4\r\n 
Arju\r\n 
5\r\n 
_rock\r\n 
0\r\n 
\r\n 

So, first 3 characters are length of data transferred and then carriage return and then newline character.

我貼被錯誤中斷,因爲Azure中也發送之前壓縮字符串的ASCII字符數據

+0

請將此回覆標記爲答案,以便解決遇到類似問題的其他社區成員。 –

相關問題