cz.msebera.android.httpclient.NameValuePair Java Examples
The following examples show how to use
cz.msebera.android.httpclient.NameValuePair.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpUtilsAsync.java From UltimateAndroid with Apache License 2.0 | 6 votes |
/** * Upload files with {@link com.loopj.android.http.SyncHttpClient} * * @param url * @param paramsList * @param fileParams * @param files * @param responseHandler */ public static void uploadFiles(String url, List<NameValuePair> paramsList, String fileParams, List<File> files, AsyncHttpResponseHandler responseHandler) throws Exception { SyncHttpClient syncHttpClient = new SyncHttpClient(); RequestParams params = new RequestParams(); if (BasicUtils.judgeNotNull(paramsList)) { for (NameValuePair nameValuePair : paramsList) { params.put(nameValuePair.getName(), nameValuePair.getValue()); } } if (BasicUtils.judgeNotNull(files)) params.put(fileParams, files); syncHttpClient.setTimeout(timeout); syncHttpClient.post(url, params, responseHandler); }
Example #2
Source File: InfinityModule.java From Overchan-Android with GNU General Public License v3.0 | 6 votes |
private void checkCaptcha(String answer, CancellableTask task) throws Exception { try { if (torCaptchaCookie == null) throw new Exception("Invalid captcha"); String url = getUsingUrl() + "dnsbls_bypass.php"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("captcha_text", answer)); pairs.add(new BasicNameValuePair("captcha_cookie", torCaptchaCookie)); HttpRequestModel rqModel = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setTimeout(30000).build(); String response = HttpStreamer.getInstance().getStringFromUrl(url, rqModel, httpClient, null, task, true); if (response.contains("Error") && !response.contains("Success")) throw new HttpWrongStatusCodeException(400, "400"); needTorCaptcha = false; } catch (HttpWrongStatusCodeException e) { if (task != null && task.isCancelled()) throw new InterruptedException("interrupted"); if (e.getStatusCode() == 400) throw new Exception("You failed the CAPTCHA"); throw e; } }
Example #3
Source File: DvachnetModule.java From Overchan-Android with GNU General Public License v3.0 | 6 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getUsingUrl() + "cgi/delete"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("board", model.boardName)); pairs.add(new BasicNameValuePair("delete_" + model.postNumber, model.postNumber)); pairs.add(new BasicNameValuePair("task", "delete")); pairs.add(new BasicNameValuePair("password", model.password)); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task); if (response.statusCode == 302) { return null; } throw new Exception(response.statusCode + " - " + response.statusReason); } finally { if (response != null) response.release(); } }
Example #4
Source File: Chan410Module.java From Overchan-Android with GNU General Public License v3.0 | 6 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = CHAN410_URL + "board.php"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("board", model.boardName)); pairs.add(new BasicNameValuePair("delete[]", model.postNumber)); if (model.onlyFiles) pairs.add(new BasicNameValuePair("fileonly", "on")); pairs.add(new BasicNameValuePair("postpassword", model.password)); pairs.add(new BasicNameValuePair("deletepost", "Удалить")); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); String result = HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, listener, task, false); if (result.contains("Неверный пароль")) throw new Exception("Неверный пароль"); return null; }
Example #5
Source File: CirnoModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = IICHAN_URL + "cgi-bin/wakaba.pl/" + model.boardName + "/"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("delete", model.postNumber)); pairs.add(new BasicNameValuePair("task", "delete")); if (model.onlyFiles) pairs.add(new BasicNameValuePair("fileonly", "on")); pairs.add(new BasicNameValuePair("password", model.password)); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task); if (response.statusCode == 200) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copyStream(response.stream, output); String htmlResponse = output.toString("UTF-8"); if (!htmlResponse.contains("<blockquote")) { int start = htmlResponse.indexOf("<h1 style=\"text-align: center\">"); if (start != -1) { int end = htmlResponse.indexOf("<br /><br />", start + 31); if (end != -1) { throw new Exception(htmlResponse.substring(start + 31, end).trim()); } } } } } finally { if (response != null) response.release(); } return null; }
Example #6
Source File: HttpUtilsAsync.java From UltimateAndroid with Apache License 2.0 | 5 votes |
/** * Upload file with {@link com.loopj.android.http.SyncHttpClient} * * @param url * @param paramsList * @param fileParams * @param file * @param responseHandler * @throws FileNotFoundException */ public static void uploadFile(String url, List<NameValuePair> paramsList, String fileParams, File file, AsyncHttpResponseHandler responseHandler) throws FileNotFoundException { SyncHttpClient syncHttpClient = new SyncHttpClient(); RequestParams params = new RequestParams(); if (BasicUtils.judgeNotNull(paramsList)) { for (NameValuePair nameValuePair : paramsList) { params.put(nameValuePair.getName(), nameValuePair.getValue()); } } if (BasicUtils.judgeNotNull(file)) params.put(fileParams, file); syncHttpClient.setTimeout(timeout); syncHttpClient.post(url, params, responseHandler); }
Example #7
Source File: WakachanModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getUsingUrl() + model.boardName + "/wakaba.pl"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("delete", model.postNumber)); pairs.add(new BasicNameValuePair("task", "delete")); if (model.onlyFiles) pairs.add(new BasicNameValuePair("fileonly", "on")); pairs.add(new BasicNameValuePair("password", model.password)); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task); if (response.statusCode == 200) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copyStream(response.stream, output); String htmlResponse = output.toString("UTF-8"); if (!htmlResponse.contains("<blockquote")) { int start = htmlResponse.indexOf("<h1 style=\"text-align: center\">"); if (start != -1) { int end = htmlResponse.indexOf("<", start + 31); if (end != -1) { throw new Exception(htmlResponse.substring(start + 31, end).trim()); } } } } } finally { if (response != null) response.release(); } return null; }
Example #8
Source File: Null_chanModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override protected List<? extends NameValuePair> getReportFormAllValues(DeletePostModel model) { List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("board", model.boardName)); pairs.add(new BasicNameValuePair("post[]", model.postNumber)); pairs.add(new BasicNameValuePair("reportpost", "Пожаловаться")); return pairs; }
Example #9
Source File: AbstractInstant0chan.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override protected List<? extends NameValuePair> getReportFormAllValues(DeletePostModel model) { List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("board", model.boardName)); pairs.add(new BasicNameValuePair("post[]", model.postNumber)); pairs.add(new BasicNameValuePair("reportpost", "Отправить")); return pairs; }
Example #10
Source File: AnonFmModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String sendPost(SendPostModel model, ProgressListener listener, CancellableTask task) throws Exception { if (model.comment.length() > 500) throw new Exception("Максимальная длина сообщения - 500 символов"); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("cid", cid)); pairs.add(new BasicNameValuePair("left", Integer.toString(500 - model.comment.length()))); pairs.add(new BasicNameValuePair("msg", model.comment)); pairs.add(new BasicNameValuePair("check", model.captchaAnswer)); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setCustomHeaders(HTTP_HEADER_FEEDBACK).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl("http://" + DOMAIN + "/feedback", request, httpClient, null, task); if (response.statusCode == 200) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copyStream(response.stream, output); String htmlResponse = output.toString("UTF-8"); if (htmlResponse.contains("window.close,10000")) return "http://" + DOMAIN + "/#" + getCurrentThreadNumber(); if (htmlResponse.contains("Неверный код подтверждения")) throw new Exception("Неверный код подтверждения"); throw new Exception("Ошибка отправки"); } else { throw new Exception(response.statusCode + " - " + response.statusReason); } } finally { if (response != null) response.release(); } }
Example #11
Source File: UchanModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getUsingUrl() + model.boardName + "/wakaba.pl"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("delete", model.postNumber)); pairs.add(new BasicNameValuePair("task", "delete")); if (model.onlyFiles) pairs.add(new BasicNameValuePair("fileonly", "on")); pairs.add(new BasicNameValuePair("password", model.password)); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task); if (response.statusCode == 200) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copyStream(response.stream, output); String htmlResponse = output.toString("UTF-8"); if (!htmlResponse.contains("<blockquote")) { int start = htmlResponse.indexOf("<h1 style=\"text-align: center\">"); if (start != -1) { int end = htmlResponse.indexOf("<br /><br />", start + 31); if (end != -1) { throw new Exception(htmlResponse.substring(start + 31, end).trim()); } } } } else if (response.statusCode == 403) { throw new Exception("Доступ заборонено"); } } finally { if (response != null) response.release(); } return null; }
Example #12
Source File: DvachModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getUsingUrl() + model.boardName + "/delete"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("posts[]", model.postNumber)); pairs.add(new BasicNameValuePair("password", model.password)); pairs.add(new BasicNameValuePair("deletepost", "Удалить")); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); String result = HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, listener, task, false); if (result.contains("Неверный пароль")) throw new Exception("Неверный пароль"); return null; }
Example #13
Source File: DFWKModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override protected List<? extends NameValuePair> getDeleteFormAllValues(DeletePostModel model) { List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("board", model.boardName)); pairs.add(new BasicNameValuePair("del_" + model.postNumber, model.postNumber)); if (model.onlyFiles) pairs.add(new BasicNameValuePair("fileonly", "on")); pairs.add(new BasicNameValuePair("postpassword", model.password)); pairs.add(new BasicNameValuePair("deletepost", "Удалить")); return pairs; }
Example #14
Source File: InachModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getUsingUrl() + model.boardName + "/wakaba.pl"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("delete", model.postNumber)); pairs.add(new BasicNameValuePair("parent", model.threadNumber)); pairs.add(new BasicNameValuePair("task", "delete")); if (model.onlyFiles) pairs.add(new BasicNameValuePair("fileonly", "on")); pairs.add(new BasicNameValuePair("password", model.password)); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task); if (response.statusCode == 200) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copyStream(response.stream, output); String htmlResponse = output.toString("UTF-8"); if (!htmlResponse.contains("<blockquote")) { int start = htmlResponse.indexOf("<h1 style='text-align: center'>"); if (start != -1) { int end = htmlResponse.indexOf("<br><br>", start + 31); if (end != -1) { throw new Exception(htmlResponse.substring(start + 31, end).trim()); } } } } } finally { if (response != null) response.release(); } return null; }
Example #15
Source File: JsonHelper.java From wallpaperboard with Apache License 2.0 | 5 votes |
@NonNull public static String getQuery(List<NameValuePair> params) throws UnsupportedEncodingException { StringBuilder result = new StringBuilder(); boolean first = true; for (NameValuePair pair : params) { if (first) first = false; else result.append("&"); result.append(URLEncoder.encode(pair.getName(), "UTF-8")); result.append("="); result.append(URLEncoder.encode(pair.getValue(), "UTF-8")); } return result.toString(); }
Example #16
Source File: Chan410Module.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String reportPost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = CHAN410_URL + "board.php"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("board", model.boardName)); pairs.add(new BasicNameValuePair("delete[]", model.postNumber)); pairs.add(new BasicNameValuePair("reportpost", "Пожаловаться")); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); String result = HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, listener, task, false); if (result.contains("Post successfully reported")) return null; throw new Exception(result); }
Example #17
Source File: NowereModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getUsingUrl() + model.boardName + "/wakaba.pl"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("delete", model.postNumber)); pairs.add(new BasicNameValuePair("task", "delete")); if (model.onlyFiles) pairs.add(new BasicNameValuePair("fileonly", "on")); pairs.add(new BasicNameValuePair("password", model.password)); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task); if (response.statusCode == 200) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copyStream(response.stream, output); String htmlResponse = output.toString("UTF-8"); if (!htmlResponse.contains("<blockquote")) { int start = htmlResponse.indexOf("<h1 style=\"text-align: center\">"); if (start != -1) { int end = htmlResponse.indexOf("<br /><br />", start + 31); if (end != -1) { throw new Exception(htmlResponse.substring(start + 31, end).trim()); } } } } } finally { if (response != null) response.release(); } return null; }
Example #18
Source File: DobroModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getDomainUrl() + model.boardName + "/delete"; String threadAPIUrl = getDomainUrl() + "api/thread/" + model.boardName + "/" + model.threadNumber + ".json"; String threadId = Long.toString(downloadJSONObject(threadAPIUrl, false, null, task).getLong("thread_id")); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair(model.postNumber, threadId)); pairs.add(new BasicNameValuePair("task", "delete")); pairs.add(new BasicNameValuePair("password", model.password)); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task); if (response.statusCode == 200) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copyStream(response.stream, output); String htmlResponse = output.toString("UTF-8"); Matcher errorMatcher = Pattern.compile("<center><h2>([^<]*)<").matcher(htmlResponse); if (errorMatcher.find()) throw new Exception(errorMatcher.group(1)); } } finally { if (response != null) response.release(); saveHanabiraCookie(); } return null; }
Example #19
Source File: AbstractKusabaModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
protected List<? extends NameValuePair> getReportFormAllValues(DeletePostModel model) throws Exception { List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("board", model.boardName)); pairs.add(new BasicNameValuePair("post[]", model.postNumber)); pairs.add(new BasicNameValuePair("reportreason", model.reportReason)); pairs.add(new BasicNameValuePair("reportpost", getReportFormValue(model))); return pairs; }
Example #20
Source File: AbstractKusabaModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
protected List<? extends NameValuePair> getDeleteFormAllValues(DeletePostModel model) throws Exception { List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("board", model.boardName)); pairs.add(new BasicNameValuePair("post[]", model.postNumber)); if (model.onlyFiles) pairs.add(new BasicNameValuePair("fileonly", "on")); pairs.add(new BasicNameValuePair("postpassword", model.password)); pairs.add(new BasicNameValuePair("deletepost", getDeleteFormValue(model))); return pairs; }
Example #21
Source File: AbstractKusabaModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String reportPost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getBoardScriptUrl(model); List<? extends NameValuePair> pairs = getReportFormAllValues(model); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); String result = HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, listener, task, false); checkReportPostResult(model, result); return null; }
Example #22
Source File: AbstractKusabaModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getBoardScriptUrl(model); List<? extends NameValuePair> pairs = getDeleteFormAllValues(model); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); String result = HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, listener, task, false); checkDeletePostResult(model, result); return null; }
Example #23
Source File: AbstractVichanModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String reportPost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getUsingUrl() + "post.php"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("board", model.boardName)); pairs.add(new BasicNameValuePair("delete_" + model.postNumber, "on")); pairs.add(new BasicNameValuePair("password", "")); pairs.add(new BasicNameValuePair("reason", model.reportReason)); pairs.add(new BasicNameValuePair("report", getReportFormValue(model))); UrlPageModel refererPage = new UrlPageModel(); refererPage.type = UrlPageModel.TYPE_THREADPAGE; refererPage.chanName = getChanName(); refererPage.boardName = model.boardName; refererPage.threadNumber = model.threadNumber; Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, buildUrl(refererPage)) }; HttpRequestModel rqModel = HttpRequestModel.builder(). setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setCustomHeaders(customHeaders).setNoRedirect(true).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, rqModel, httpClient, listener, task); if (response.statusCode == 200 || response.statusCode == 400 || response.statusCode == 303) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copyStream(response.stream, output); String htmlResponse = output.toString("UTF-8"); Matcher errorMatcher = ERROR_PATTERN.matcher(htmlResponse); if (errorMatcher.find()) throw new Exception(errorMatcher.group(1)); return null; } throw new Exception(response.statusCode + " - " + response.statusReason); } finally { if (response != null) response.release(); } }
Example #24
Source File: AbstractVichanModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getUsingUrl() + "post.php"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("board", model.boardName)); pairs.add(new BasicNameValuePair("delete_" + model.postNumber, "on")); if (model.onlyFiles) pairs.add(new BasicNameValuePair("file", "on")); pairs.add(new BasicNameValuePair("password", model.password)); pairs.add(new BasicNameValuePair("delete", getDeleteFormValue(model))); pairs.add(new BasicNameValuePair("reason", "")); UrlPageModel refererPage = new UrlPageModel(); refererPage.type = UrlPageModel.TYPE_THREADPAGE; refererPage.chanName = getChanName(); refererPage.boardName = model.boardName; refererPage.threadNumber = model.threadNumber; Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, buildUrl(refererPage)) }; HttpRequestModel rqModel = HttpRequestModel.builder(). setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setCustomHeaders(customHeaders).setNoRedirect(true).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, rqModel, httpClient, listener, task); if (response.statusCode == 200 || response.statusCode == 400 || response.statusCode == 303) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copyStream(response.stream, output); String htmlResponse = output.toString("UTF-8"); Matcher errorMatcher = ERROR_PATTERN.matcher(htmlResponse); if (errorMatcher.find()) throw new Exception(errorMatcher.group(1)); return null; } throw new Exception(response.statusCode + " - " + response.statusReason); } finally { if (response != null) response.release(); } }
Example #25
Source File: KrautModule.java From Overchan-Android with GNU General Public License v3.0 | 4 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = (useHttps() ? "https://" : "http://") + CHAN_DOMAIN + "/delete"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("post_" + model.postNumber, "delete")); pairs.add(new BasicNameValuePair("password", model.password)); pairs.add(new BasicNameValuePair("board", model.boardName)); HttpRequestModel request = HttpRequestModel.builder().setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setNoRedirect(true).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task); if (response.statusCode == 302) { for (Header header : response.headers) { if (header != null && HttpHeaders.LOCATION.equalsIgnoreCase(header.getName())) { String location = header.getValue(); if (location.contains("banned")) throw new Exception("You are banned"); break; } } return null; } else if (response.statusCode == 200) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copyStream(response.stream, output); String htmlResponse = output.toString("UTF-8"); int messageNoticePos = htmlResponse.indexOf("class=\"message_notice"); if (messageNoticePos == -1) return null; int p2 = htmlResponse.indexOf('>', messageNoticePos); if (p2 != -1) { String errorMessage = htmlResponse.substring(p2 + 1); int p3 = errorMessage.indexOf("</tr>"); if (p3 != -1) errorMessage = errorMessage.substring(0, p3); errorMessage = RegexUtils.trimToSpace(StringEscapeUtils.unescapeHtml4(RegexUtils.removeHtmlTags(errorMessage)).trim()); throw new Exception(errorMessage); } } throw new HttpWrongStatusCodeException(response.statusCode, response.statusCode + " - " + response.statusReason); } finally { if (response != null) response.release(); } }
Example #26
Source File: InfinityModule.java From Overchan-Android with GNU General Public License v3.0 | 4 votes |
@Override public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getUsingUrl() + "post.php"; List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("board", model.boardName)); pairs.add(new BasicNameValuePair("delete_" + model.postNumber, "on")); if (model.onlyFiles) pairs.add(new BasicNameValuePair("file", "on")); pairs.add(new BasicNameValuePair("password", model.password)); pairs.add(new BasicNameValuePair("delete", "Delete")); pairs.add(new BasicNameValuePair("reason", "")); UrlPageModel refererPage = new UrlPageModel(); refererPage.type = UrlPageModel.TYPE_THREADPAGE; refererPage.chanName = getChanName(); refererPage.boardName = model.boardName; refererPage.threadNumber = model.threadNumber; Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, buildUrl(refererPage)) }; HttpRequestModel rqModel = HttpRequestModel.builder(). setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setCustomHeaders(customHeaders).setNoRedirect(true).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, rqModel, httpClient, listener, task); if (response.statusCode == 200 || response.statusCode == 303) { Logger.d(TAG, response.statusCode + " - " + response.statusReason); return null; } else if (response.statusCode == 400) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copyStream(response.stream, output); String htmlResponse = output.toString("UTF-8"); if (htmlResponse.contains("dnsbls_bypass.php")) { needTorCaptcha = true; throw new Exception("Please complete your CAPTCHA.\n(try to post anything)"); } else if (htmlResponse.contains("<h1>Error</h1>")) { Matcher errorMatcher = ERROR_PATTERN.matcher(htmlResponse); if (errorMatcher.find()) { String error = errorMatcher.group(1); if (error.contains("To post on 8chan over Tor, you must use the hidden service for security reasons.")) throw new Exception(resources.getString(R.string.infinity_tor_message)); //? Tor users cannot into deleting throw new Exception(error); } } } throw new Exception(response.statusCode + " - " + response.statusReason); } finally { if (response != null) response.release(); } }
Example #27
Source File: JsonStructure.java From wallpaperboard with Apache License 2.0 | 4 votes |
@NonNull public List<NameValuePair> getPosts() { return mBuilder.mValues; }