mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
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:
parent
c5fd1e8fd1
commit
d7ad63ad38
3 changed files with 12 additions and 1 deletions
Binary file not shown.
|
|
@ -2,7 +2,10 @@ package org.wikimedia.commons;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import org.mediawiki.api.*;
|
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.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.params.CoreProtocolPNames;
|
||||||
|
|
||||||
public class CommonsApplication extends Application {
|
public class CommonsApplication extends Application {
|
||||||
|
|
||||||
|
|
@ -13,7 +16,13 @@ public class CommonsApplication extends Application {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
DefaultHttpClient client = new DefaultHttpClient();
|
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() {
|
public MWApi getApi() {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import org.w3c.dom.Document;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.provider.MediaStore;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
@ -80,6 +81,7 @@ public class ShareActivity extends Activity {
|
||||||
// return str;
|
// return str;
|
||||||
return result.getString("/api/upload/@result");
|
return result.getString("/api/upload/@result");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
return "Failure";
|
return "Failure";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue