cz.msebera.android.httpclient.client.entity.UrlEncodedFormEntity Java Examples

The following examples show how to use cz.msebera.android.httpclient.client.entity.UrlEncodedFormEntity. 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 vote down vote up
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 vote down vote up
@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 vote down vote up
@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 vote down vote up
@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 vote down vote up
@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: AnonFmModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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 #7
Source File: UchanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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 #8
Source File: DvachModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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 #9
Source File: InachModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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 #10
Source File: CirnoModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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 #11
Source File: AbstractVichanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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 #12
Source File: NowereModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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 #13
Source File: DobroModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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 #14
Source File: AbstractKusabaModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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 #15
Source File: AbstractKusabaModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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 #16
Source File: AbstractVichanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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 #17
Source File: KrautModule.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
@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 #18
Source File: Chan420Module.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
@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 #19
Source File: InfinityModule.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
@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();
    }
}