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-- 

これを確実に行う方法はありますか?

+0

あなたのリクエストはどのように見えますか?あなたは 'application/json'をリクエストしていますか?これは応答の完全な開始ですか?それは正しくない、 'Content-Type'は境界タグを含むべきです。あなたはhttpclientでどのように応答データを読みますか? – PeterMmm

+0

@PeterMmm私は "application/json; charset = utf-8"を要求しています。私は質問を編集し、完全な応答を投稿しました。 JSONコンテンツが100%のように見え、{JSON} – Arya

+0

に変更されました。レスポンスは '--Boundary_16003419 ... 'で始まりますか?このサーバーとは何ですか?あなたはそれを制御しますか? – PeterMmm

答えて

2

1つのオプションはApache Mime4jです。メモリ内に完全なDOMツリーを構築せずにアプリケーションが応答コンテンツを処理したい場合は、hereのようにMimeTokenStreamまたはMimeStreamParserを使用することをお勧めします。

関連する問題