2012-06-25 29 views
8

我正在使用web客戶端。並通過Web客戶端成功登錄。但是當我發送獲取數據的第二個請求。我得到了一個例外如何使用httpunit獲取json頁面

[email protected]` 

但是當我通過url thruogh brouser我有一個數據JSON格式。

代碼:

webClient.getPage("http://ajax/stream/refresh-box?r=new&id=2323222&") 

THX的先進

+0

http://stackoverflow.com/questions/2932857/html-handling-a-json-response –

+0

請你添加一個JUnit測試用例來展示你的問題的重點? –

回答

1

這是它通過Web客戶端讀取不同的內容類型

Page page = webClient.getPage(url); 
System.out.println(page); 
WebResponse response = page.getWebResponse(); 

if (response.getContentType().equals("application/json")) 
{ 
pagesource = response.getContentAsString(); 
System.out.println(pagesource); 
} 
0

此URL返回一個錯誤,如果我在瀏覽器中鍵入,檢查一遍: 的「http:// AJAX /流/刷新-box?R =新& ID = 2323222 &「

BTW,爲什麼它有&符號完成,而沒有額外的參數?

我刪除了&標誌,我仍然獲得在瀏覽器頁面沒有例外。