Search in sources :

Example 46 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project restfuse by eclipsesource.

the class Response_Test method mockRequest.

private HttpRequest mockRequest() throws MalformedURLException {
    HttpRequest httpRequest = mock(HttpRequest.class);
    HttpURLConnection connection = mock(HttpURLConnection.class);
    when(connection.getURL()).thenReturn(new URL("http://test.com"));
    when(httpRequest.getConnection()).thenReturn(connection);
    when(httpRequest.body()).thenReturn("test");
    when(httpRequest.code()).thenReturn(200);
    when(httpRequest.contentType()).thenReturn(MediaType.TEXT_PLAIN.toString());
    HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
    List<String> values = new ArrayList<String>();
    values.add("test");
    headers.put("test", values);
    when(httpRequest.headers()).thenReturn(headers);
    return httpRequest;
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) HttpURLConnection(java.net.HttpURLConnection) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) URL(java.net.URL)

Example 47 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project restfuse by eclipsesource.

the class InternalRequest method put.

public Response put() {
    HttpRequest request = HttpRequest.put(url);
    addContentType(request);
    addHeaders(request);
    addAuthentication(request);
    request.send(content);
    sendRequest(request);
    return new ResponseImpl(request);
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest)

Example 48 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project restfuse by eclipsesource.

the class InternalRequest method options.

public Response options() {
    HttpRequest request = HttpRequest.options(url);
    addContentType(request);
    addHeaders(request);
    addAuthentication(request);
    sendRequest(request);
    return new ResponseImpl(request);
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest)

Example 49 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project restfuse by eclipsesource.

the class InternalRequest method delete.

public Response delete() {
    HttpRequest request = HttpRequest.delete(url);
    addContentType(request);
    addHeaders(request);
    addAuthentication(request);
    sendRequest(request);
    return new ResponseImpl(request);
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest)

Example 50 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project scdl by passy.

the class AbstractSoundcloudApiQueryImpl method executePost.

/**
 * Executes the POST request. Instead of using the bare HttpURLConnection
 * API, we use our modified HttpRequest client to be able to upload with
 * multipart and other cool things.
 *
 * @return
 * @throws APIException
 */
protected HttpURLConnection executePost() throws APIException {
    Ln.d("Executing POST against URL " + mUrl.toString());
    final HttpRequest request = HttpRequest.post(mUrl);
    setupPostRequest(request);
    if (mSendCallback != null) {
        request.setSendCallback(mSendCallback);
    }
    if (mPartParameters.size() > 0) {
        applyPostParametersAsPart(request);
        applyPartParameters(request);
    } else {
        applyPostParameters(request);
    }
    try {
        request.closeOutput();
    } catch (final IOException e) {
        throw new APIException(e, -1);
    }
    return request.getConnection();
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) IOException(java.io.IOException)

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