cz.msebera.android.httpclient.message.BasicNameValuePair Java Examples
The following examples show how to use
cz.msebera.android.httpclient.message.BasicNameValuePair.
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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
Source File: NameValuePair.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** * Converts the specified name/value pairs into HttpClient name/value pairs. * @param pairs the name/value pairs to convert * @return the converted name/value pairs */ public static cz.msebera.android.httpclient.NameValuePair[] toHttpClient(final NameValuePair[] pairs) { final cz.msebera.android.httpclient.NameValuePair[] pairs2 = new cz.msebera.android.httpclient.NameValuePair[pairs.length]; for (int i = 0; i < pairs.length; i++) { final NameValuePair pair = pairs[i]; pairs2[i] = new BasicNameValuePair(pair.getName(), pair.getValue()); } return pairs2; }
Example #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
Source File: NameValuePair.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** * Converts the specified name/value pairs into HttpClient name/value pairs. * @param pairs the name/value pairs to convert * @return the converted name/value pairs */ public static cz.msebera.android.httpclient.NameValuePair[] toHttpClient(final List<NameValuePair> pairs) { final cz.msebera.android.httpclient.NameValuePair[] pairs2 = new cz.msebera.android.httpclient.NameValuePair[pairs.size()]; for (int i = 0; i < pairs.size(); i++) { final NameValuePair pair = pairs.get(i); pairs2[i] = new BasicNameValuePair(pair.getName(), pair.getValue()); } return pairs2; }
Example #22
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 #23
Source File: Chan420Module.java From Overchan-Android with GNU General Public License v3.0 | 4 votes |
@Override public String sendPost(SendPostModel model, ProgressListener listener, CancellableTask task) throws Exception { int bVal = (int) (Math.random() * 10000); String banana = HttpStreamer.getInstance().getJSONObjectFromUrl((useHttps() ? "https://" : "http://") + "boards.420chan.org/bunker/", HttpRequestModel.builder(). setPOST(new UrlEncodedFormEntity(Collections.singletonList(new BasicNameValuePair("b", Integer.toString(bVal))), "UTF-8")). setCustomHeaders(new Header[] { new BasicHeader("X-Requested-With", "XMLHttpRequest") }). build(), httpClient, null, task, false).optString("response"); String url = (useHttps() ? "https://" : "http://") + "boards.420chan.org/" + model.boardName + "/taimaba.pl"; ExtendedMultipartBuilder postEntityBuilder = ExtendedMultipartBuilder.create().setDelegates(listener, task). addString("board", model.boardName). addString("task", "post"). addString("password", model.password); if (model.threadNumber != null) postEntityBuilder.addString("parent", model.threadNumber); postEntityBuilder. addString("field1", model.name). addString("field3", model.subject). addString("field4", model.comment); if (model.attachments != null && model.attachments.length > 0) postEntityBuilder.addFile("file", model.attachments[0], model.randomHash); if (model.sage) postEntityBuilder.addString("sage", "on"); postEntityBuilder.addString("banana", banana); HttpRequestModel request = HttpRequestModel.builder().setPOST(postEntityBuilder.build()).setNoRedirect(true).build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task); if (response.statusCode == 302) { return null; } else if (response.statusCode == 200) { 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)); } else throw new Exception(response.statusCode + " - " + response.statusReason); } finally { if (response != null) response.release(); } return null; }
Example #24
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 #25
Source File: JsonStructure.java From wallpaperboard with Apache License 2.0 | 4 votes |
public Builder post(@NonNull String tag, @NonNull String value) { mValues.add(new BasicNameValuePair(tag, value)); return this; }