Make uploads work with WMF wikis

They use HTTP/1.0, so no HTTP Chunked Transfer. Took me a fucklong
to actually find that out - almost 5 hours as I chased wrong leads,
looked for bugs in the HTTP libs, battled poor network, etc. But
was relatively easy to spot once I started logging HTTP requests.

Now, if only Java had a decent documentation browser...
This commit is contained in:
YuviPanda 2012-10-07 01:20:28 +05:30
parent c5fd1e8fd1
commit d7ad63ad38
3 changed files with 12 additions and 1 deletions

View file

@ -2,7 +2,10 @@ package org.wikimedia.commons;
import android.app.Application;
import org.mediawiki.api.*;
import org.apache.http.HttpVersion;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
public class CommonsApplication extends Application {
@ -13,7 +16,13 @@ public class CommonsApplication extends Application {
// TODO Auto-generated method stub
super.onCreate();
DefaultHttpClient client = new DefaultHttpClient();
api = new MWApi("http://192.168.1.34/w/api.php", client);
// Because WMF servers support only HTTP/1.0. Biggest difference that
// this makes is support for Chunked Transfer Encoding.
// I have this here so if any 1.1 features start being used, it
// throws up.
client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
HttpVersion.HTTP_1_0);
api = new MWApi("http://test.wikipedia.org/w/api.php", client);
}
public MWApi getApi() {