2
我正在使用Apache HttpClient處理返回包含json的multipart/form-data響應的Web服務。從多部分HTTP響應中提取多個JSON字符串
我有一個非常困難的時間分別提取每個JSON字符串,所以我可以閱讀JSON字符串。
我的確看過Stackoverflow上的類似帖子,有人建議使用Apache commons fileupload,但我不確定如何將JSON字符串從整個響應中分離出來,這些響應包含一系列其他文本,如邊界字符串,內容類型等
響應如下所示。
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetMailboxes
Status-Code: 200
X-Server-Response-Time: 4ms
X-Server-Chain: domain.com
Content-RequestDuration: 5
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetFolders
Status-Code: 200
X-Server-Response-Time: 8ms
X-Server-Chain: domain.com
Content-RequestDuration: 10
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetAlerts
Status-Code: 200
X-Server-Response-Time: 10ms
X-Server-Chain: domain.com
Content-RequestDuration: 12
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetAccounts
Status-Code: 200
X-Server-Response-Time: 11ms
X-Server-Chain: domain.com
Content-RequestDuration: 12
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetAllSavedSearches
Status-Code: 200
X-Server-Response-Time: 10ms
X-Server-Chain: domain.com
Content-RequestDuration: 12
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetAthenaSegment
Status-Code: 200
X-Server-Response-Time: 14ms
Content-RequestDuration: 21
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: ListFolderThreads
Status-Code: 200
X-Server-Response-Time: 110ms
Content-RequestDuration: 116
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetUserInfo
Status-Code: 200
X-Server-Response-Time: 197ms
Content-RequestDuration: 204
{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-RequestId: Status
Content-Type: application/json
{JSON}
--Boundary_16003419_2104021487_1483424496169--
任何方式可靠地做到這一點?
你的要求是什麼樣子?你正在申請'application/json'?這是迴應的完整開始嗎?它看起來不正確,'Content-Type'應該包含邊界標籤。你如何使用httpclient讀取響應數據? – PeterMmm
@PeterMmm我正在請求「application/json; charset = utf-8」我編輯了這個問題併發布了完整的響應。多數民衆贊成它是如何100%的JSON內容更改爲{JSON} – Arya
響應以'--Boundary_16003419 ...'開始?這臺服務器是什麼?你控制它嗎? – PeterMmm