Search in sources :

Example 76 with HttpRequest

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

the class SeafConnection method getHistoryChanges.

public String getHistoryChanges(String repoID, String commitId) throws SeafException {
    try {
        String apiPath = String.format("api2/repo_history_changes/%s/", repoID);
        Map<String, Object> params = Maps.newHashMap();
        params.put("commit_id", commitId);
        HttpRequest req = prepareApiGetRequest(apiPath, params);
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
        String result = new String(req.bytes(), "UTF-8");
        return result;
    } catch (SeafException e) {
        throw e;
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    } catch (IOException e) {
        throw SeafException.networkException;
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) JSONObject(org.json.JSONObject) IOException(java.io.IOException)

Example 77 with HttpRequest

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

the class SeafConnection method deleteShareLink.

public boolean deleteShareLink(String token) throws SeafException {
    try {
        HttpRequest req = prepareApiDeleteRequest(String.format("api/v2.1/share-links/%s/", token), null);
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
        String result = new String(req.bytes(), "UTF-8");
        if (result != null && Utils.parseJsonObject(result) != null) {
            JSONObject obj = Utils.parseJsonObject(result);
            return obj.getBoolean("success");
        } else {
            throw SeafException.illFormatException;
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) JSONObject(org.json.JSONObject) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JSONException(org.json.JSONException)

Example 78 with HttpRequest

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

the class SeafConnection method unstar.

public void unstar(String repoID, String path) throws SeafException {
    try {
        Map<String, Object> params = Maps.newHashMap();
        params.put("repo_id", repoID);
        params.put("p", path);
        HttpRequest req = prepareApiDeleteRequest("api2/starredfiles/", params);
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
    } catch (SeafException e) {
        throw e;
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) JSONObject(org.json.JSONObject)

Example 79 with HttpRequest

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

the class SeafConnection method getAccountInfo.

/**
 * <p>
 * get Account info, which consists of three fields, usage, total and email.
 * </p>
 * use GET to send HTTP request.
 *
 * @return
 * @throws SeafException
 */
public String getAccountInfo() throws SeafException {
    String result;
    try {
        HttpRequest req = prepareApiGetRequest("api2/account/info/");
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
        result = new String(req.bytes(), "UTF-8");
    } catch (SeafException e) {
        throw e;
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    } catch (IOException e) {
        throw SeafException.networkException;
    }
    return result;
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) IOException(java.io.IOException)

Example 80 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project sunlogin-exp-gui by theLSA.

the class GetSunloginInfo method get_fastcode.

public String get_fastcode() {
    /*
		class FastCodeClass{
			public String fastcode;
		}
		*/
    String fastcode = "";
    try {
        HttpRequest responseRst = HttpRequest.get(url).connectTimeout(httpTimeout).readTimeout(httpTimeout);
        String responseBody = responseRst.body();
        fastcode = responseBody;
    } catch (Exception e) {
        // TODO: handle exception
        SunloginExpGui.expResultTextArea.append("get_fastcode failed. Caused exception.\n");
    }
    // FastCodeClass fcc = new Gson().fromJson(responseBody, FastCodeClass.class);
    return fastcode;
}
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