views:

248

answers:

2

I'm using the mediawiki Api to update some pages with an experimental robot. This robot uses the java apache http-client library to update the pages.

(...)
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);
(...)

however the 'content' String contains some accents. System.out.prinln(content) looks ok, but the accentuated characters in the wiki look bad. E.g. 'Val�rie' instead of 'Valérie'.

How can I fix this ?

A: 

In my PHP code to talk to the Mediawiki API I used urlencode to encode the title parameter, and this seems to work fine.

rdmpage
Hi Roderic :-)Thanks but, I don't think this is the problem. The 'addParameters' methods already converts the data when it sends the POST query. May be the solution is here: http://tinyurl.com/lyxv8c. I'll check tomorrow.
Pierre
+3  A: 

OK, changing the request header fixed the problem.

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