Search in sources :

Example 61 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project domain_hunter_pro by bit4woo.

the class VMP method upload.

public static boolean upload(String ApiUrl, HashMap<String, String> header, String jsonData) {
    HttpRequest request = HttpRequest.post(ApiUrl);
    // request.useProxy("localhost", 8080);//注意burp启用HTTP2的功能,会影响返回包的解析
    request.trustAllCerts();
    request.headers(header);
    request = request.send(jsonData);
    String body = "";
    request.body(body);
    int code = request.code();
    // System.out.print(code);
    if (code == 201 || code == 200) {
        System.out.println(jsonData + "   " + true);
        return true;
    } else {
        System.out.println(jsonData + "   code:" + code + " body:" + body);
        return false;
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest)

Example 62 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class AuthImageDownloader method getStreamFromNetwork.

@Override
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
    HttpRequest req = HttpRequest.get(imageUri, null, false).readTimeout(readTimeout).connectTimeout(connectTimeout).followRedirects(true).header("Authorization", "Token " + ((Account) extra).token);
    HttpURLConnection conn = req.getConnection();
    if (conn instanceof HttpsURLConnection) {
        // Tell HttpRequest to trust all hosts, and then the user will get a dialog
        // where he needs to confirm the SSL certificate for the account,
        // and the accepted certificate will be stored, so he is not prompted to accept later on.
        // This is handled by SSLTrustManager and CertsManager
        req.trustAllHosts();
        HttpsURLConnection sconn = (HttpsURLConnection) conn;
        sconn.setSSLSocketFactory(SSLTrustManager.instance().getSSLSocketFactory((Account) extra));
    }
    return new FlushedInputStream(new BufferedInputStream(req.stream()));
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) Account(com.seafile.seadroid2.account.Account) FlushedInputStream(com.nostra13.universalimageloader.core.assist.FlushedInputStream) HttpURLConnection(java.net.HttpURLConnection) BufferedInputStream(java.io.BufferedInputStream) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 63 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method rename.

public Pair<String, String> rename(String repoID, String path, String newName, boolean isdir) throws SeafException {
    try {
        Map<String, Object> params = Maps.newHashMap();
        params.put("p", encodeUriComponent(path).replaceAll("\\+", "%20"));
        params.put("reloaddir", "true");
        String suffix = isdir ? "/dir/" : "/file/";
        HttpRequest req = prepareApiPostRequest("api2/repos/" + repoID + suffix, true, params);
        req.form("operation", "rename");
        req.form("newname", newName);
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
        String newDirID = req.header("oid");
        if (newDirID == null) {
            return null;
        }
        String content = new String(req.bytes(), "UTF-8");
        if (content.length() == 0) {
            return null;
        }
        return new Pair<String, String>(newDirID, content);
    } catch (SeafException e) {
        throw e;
    } catch (UnsupportedEncodingException e) {
        throw SeafException.encodingException;
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) JSONObject(org.json.JSONObject) Pair(android.util.Pair)

Example 64 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method setPassword.

// set password for an encrypted repo
public boolean setPassword(String repoID, String passwd) throws SeafException {
    try {
        HttpRequest req = prepareApiPostRequest("api2/repos/" + repoID + "/", true, null);
        req.form("password", passwd);
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
        return true;
    } catch (SeafException e) {
        Log.d(DEBUG_TAG, "Set Password err: " + e.getCode());
        throw e;
    } catch (Exception e) {
        Log.d(DEBUG_TAG, "Exception in setPassword ");
        e.printStackTrace();
    }
    return false;
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) JSONException(org.json.JSONException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 65 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method prepareApiDeleteRequest.

private HttpRequest prepareApiDeleteRequest(String apiPath, Map<String, ?> params) throws HttpRequestException {
    HttpRequest req = HttpRequest.delete(account.server + apiPath, params, false).followRedirects(true).connectTimeout(CONNECTION_TIMEOUT);
    req.header("Authorization", "Token " + account.token);
    return prepareHttpsCheck(req);
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest)

Aggregations

HttpRequest (com.github.kevinsawicki.http.HttpRequest)86 HttpRequestException (com.github.kevinsawicki.http.HttpRequest.HttpRequestException)29 IOException (java.io.IOException)25 JSONObject (org.json.JSONObject)19 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 File (java.io.File)8 TimerTask (java.util.TimerTask)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 Pair (android.util.Pair)6 URL (java.net.URL)5 JSONException (org.json.JSONException)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)4 JSONObject (com.alibaba.fastjson.JSONObject)4 ZipFile (net.lingala.zip4j.ZipFile)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 IPEntity (com.example.li.springboot_crawler_demo.utils.img.entity.IPEntity)2 HttpURLConnection (java.net.HttpURLConnection)2 MalformedURLException (java.net.MalformedURLException)2 Matcher (java.util.regex.Matcher)2 JSONArray (org.json.JSONArray)2