2009-07-16 21 views
5

我正在使用MediaWiki API來更新一些實驗性機器人的頁面。 該機器人使用Java Apache HTTP客戶端庫更新頁面。MediaWiki API和編碼

(...) 
PostMethod postMethod = new PostMethod("http://mymediawikiinstallation/w/api.php"); 
postMethod.addParameter("action","edit"); 
postMethod.addParameter("title",page.replace(' ', '_')); 
postMethod.addParameter("summary","trying to fix this accent problem"); 
postMethod.addParameter("text",content); 
postMethod.addParameter("basetimestamp",basetimestamp); 
postMethod.addParameter("starttimestamp",starttimestamp); 
postMethod.addParameter("token",token); 
postMethod.addParameter("notminor",""); 
postMethod.addParameter("format","xml"); 
int status = httpClient.executeMethod(postMethod); 
(...) 

但'content'字符串包含一些重音。 System.out.prinln(content)看起來不錯,但wiki中突出顯示的字符看起來很糟糕。例如。 'Val rie'而不是'Valérie'。

我該如何解決這個問題?

回答

3

好的,更改請求頭修復了問題。

postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); 
0

在我的PHP代碼中與Mediawiki API交談時,我使用urlencode來對標題參數進行編碼,並且這似乎工作正常。

+0

嗨Roderic :-) 謝謝,但我不認爲這是問題所在。 'addParameters'方法在發送POST查詢時已經轉換了數據。可能是解決方案在這裏:http://tinyurl.com/lyxv8c。我明天再查。 – Pierre 2009-07-16 18:10:23