Partial (broken) change to okhttp for posting

captchafix2
Floens 10 years ago
parent 53d52e65a2
commit 57db717afb
  1. 2
      Clover/app/build.gradle
  2. 6
      Clover/app/src/main/java/org/floens/chan/ChanApplication.java
  3. 58
      Clover/app/src/main/java/org/floens/chan/core/manager/ReplyManager.java
  4. 5
      Clover/app/src/main/java/org/floens/chan/ui/fragment/ReplyFragment.java

@ -72,7 +72,7 @@ dependencies {
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.android.support:support-v13:18.0.0'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.0.12'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile files('libs/httpclientandroidlib-1.2.1.jar')
}

@ -45,10 +45,10 @@ import java.util.List;
public class ChanApplication extends Application {
private static final String TAG = "ChanApplication";
private static final long FILE_CACHE_DISK_SIZE = 50 * 1024 * 1024; // 50mb
private static final long FILE_CACHE_DISK_SIZE = 50 * 1024 * 1024;
private static final String FILE_CACHE_NAME = "filecache";
private static final int VOLLEY_LRU_CACHE_SIZE = 8 * 1024 * 1024; // 8mb
private static final int VOLLEY_CACHE_SIZE = 10 * 1024 * 1024; // 8mb
private static final int VOLLEY_LRU_CACHE_SIZE = 8 * 1024 * 1024;
private static final int VOLLEY_CACHE_SIZE = 10 * 1024 * 1024;
private static ChanApplication instance;
private static RequestQueue volleyRequestQueue;

@ -19,8 +19,17 @@ package org.floens.chan.core.manager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.MultipartBuilder;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import org.floens.chan.ChanApplication;
import org.floens.chan.R;
import org.floens.chan.chan.ChanUrls;
@ -323,7 +332,9 @@ public class ReplyManager {
public void getCaptchaChallenge(final CaptchaChallengeListener listener) {
HttpPost httpPost = new HttpPost(ChanUrls.getCaptchaFallback());
httpPost.addHeader("User-Agent", "Android");
httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36");
httpPost.addHeader("Referer", "https://boards.4chan.org/");
httpPost.addHeader("Cookie", "NID=67");
HttpPostSendListener postListener = new HttpPostSendListener() {
@Override
@ -391,6 +402,51 @@ public class ReplyManager {
public void onHash(String hash);
}
public String getUserAgent() {
String version = "";
try {
version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
version = version.toLowerCase(Locale.ENGLISH).replace(" ", "_");
return "Clover/" + version;
}
public void postReply(Reply reply) {
OkHttpClient client = new OkHttpClient();
MultipartBuilder formBuilder = new MultipartBuilder();
formBuilder.type(MultipartBuilder.FORM);
formBuilder.addFormDataPart("foo", "bar");
if (reply.file != null) {
formBuilder.addFormDataPart("file", "filename", RequestBody.create(
MediaType.parse("application/octet-stream"), reply.file
));
}
RequestBody form = formBuilder.build();
Request request = new Request.Builder()
.header("User-Agent", getUserAgent())
.url("")
.post(form)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Response response) throws IOException {
if (response.isSuccessful()) {
Logger.test("Output = " + response.body().string());
}
}
});
}
/**
* Send an reply off to the server.
*

@ -581,12 +581,13 @@ public class ReplyFragment extends DialogFragment {
Board b = ChanApplication.getBoardManager().getBoardByValue(loadable.board);
draft.spoilerImage = b != null && b.spoilers && spoilerImageView.isChecked();
ChanApplication.getReplyManager().sendReply(draft, new ReplyManager.ReplyListener() {
/*ChanApplication.getReplyManager().sendReply(draft, new ReplyManager.ReplyListener() {
@Override
public void onResponse(ReplyResponse response) {
handleSubmitResponse(response);
}
});
});*/
ChanApplication.getReplyManager().postReply(draft);
}
/**

Loading…
Cancel
Save