okhttp

OKHttp handle 302

和自甴很熟 提交于 2019-12-12 21:23:06
问题 Every time I perform a OKHttp Post request on this site, the response code is 302 and the response body is: <html> <head> <title>Object moved</title> </head> <body> <h2>Object moved to <a href="/GradebookSummary.aspx">here</a>. </h2> </body> </html> Here is my code: OkHttpClient client = new OkHttpClient().newBuilder() .followRedirects(false) .followSslRedirects(false) .build(); MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); RequestBody body = RequestBody.create

Retrofit2 Okhttp3 catch TimeOut

女生的网名这么多〃 提交于 2019-12-12 18:36:15
问题 I got a client like this: public enum RestClient { INSTANCE; private static final int CONNECTION_TIMEOUT = 10; private static final int READ_TIMEOUT = 30; private static final int WRITE_TIMEOUT = 30; private final Rest restClient; private RestClient() { restClient = new Retrofit.Builder() .baseUrl(App.getContext().getResources().getString(R.string.EP)) .addConverterFactory(JacksonConverterFactory.create()) .client(new okhttp3.OkHttpClient.Builder() .connectTimeout(CONNECTION_TIMEOUT, TimeUnit

Why HTTP/2 is not supported by Android's HttpUrlConnection?

笑着哭i 提交于 2019-12-12 17:31:24
问题 I just found out that Android's recommended http client HttpUrlConnection doesn't support HTTP/2. Is there a specific reason not to use HTTP/2 on Android? 回答1: You can use OkHttp if you want to take advantage of HTTP/2: https://github.com/square/okhttp It's superior to HttpUrlConnection anyway. If you're doing anything at all complicated, like getting complex JSON responses from a web API, I'd recommend Retrofit: https://square.github.io/retrofit/ 来源: https://stackoverflow.com/questions

Okhttp NoClassDefFoundError

烂漫一生 提交于 2019-12-12 10:58:19
问题 I am using OkHttp 2.0.0 jar in my android application on eclipse. As OkHttp is now dependent on Okio library, I also added Okio 1.0.0 jar in my project.The project compiles fine with no compilation errors but when I run on my android device, it gives me this NoClassDefFoundError all relating to the OkHttp library classes. I have placed all the jars in my libs folder of the project and added them to my build path and also tried checking them in the Export and Order Tab, but still it is not

Retrofit2 handling HTTP 204 (No Content response ) situation with RxJava's Observable concepts

a 夏天 提交于 2019-12-12 10:54:05
问题 I have a web-service which return a list of users for a topic, if there is no any user for that topic it just returns HTTP code 204( No Content). This is my retrofit2 call for that service (in Kotlin) @GET("/user/{topic}") fun getAllUserFor(@Path(value="topic",encoded=true) topic:String) :Observable<List<User>> And my execution is : fun getAllUsers(topic: String, onSuccess: Consumer<List<User>>, onFail:Consumer<Throwable>){ val api = NetworkLayer.getUserApi() api.getAllUserFor(topic)

OKhttp : SSLProtocolException: SSL handshake terminated

蹲街弑〆低调 提交于 2019-12-12 09:42:29
问题 I'm trying to figure out why sometimes I get this error javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0x60d46c90: Failure in SSL library, usually a protocol error error:1409443E:SSL routines:SSL3_READ_BYTES:tlsv1 alert inappropriate fallback (external/openssl/ssl/s3_pkt.c:1256 0x60d57f40:0x00000003) the code that makes this request: private <T> void send(final String url, final Map<String, String> args, final RequestCallback<T> callback, final Parser<T> pParser, final

Retrofit - Too many follow-up requests: 21

[亡魂溺海] 提交于 2019-12-12 08:23:02
问题 I'm using retrofit to make requests. I've got following error: java.net.ProtocolException: Too many follow-up requests: 21 The code is like below: private OkHttpClient httpClient; private CookieManager cookieManager; public <S> S createCookieService(Class<S> serviceClass) { httpClient.interceptors().clear(); httpClient.setCookieHandler(cookieManager); Retrofit.Builder builder = new Retrofit .Builder() .client(httpClient) .baseUrl(url) .addConverterFactory(GsonConverterFactory.create());

Android networking library: Is it still worth using Volley? [closed]

梦想的初衷 提交于 2019-12-12 03:44:36
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . This question is actually not about the coding, so I don't put any codes here. While looking into the Volley library, I found out that some part of the APIs contain classes (e.g. classes of the org.apache.http packages) that are now deprecated in Android API level 22. As I'm

getting json data from google image search api with different start numbers

风流意气都作罢 提交于 2019-12-12 03:16:33
问题 the google image search url looks like this https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=eden%20hazard&rsz=8&start=4 where the rsz parameter in the max images per page and the start parameter is the page number. I am able to get all imaged in a page. But have no idea to do that for say 20 pages, that is start= 0 ... 19. My code below shows how i did get the imaged from a page. Please let me know how i can make it get images for several pages. I tried using a for loop

OkHttp with SNI: Connection reset on Java 7

徘徊边缘 提交于 2019-12-12 02:52:45
问题 The following snippet works perfectly as long as only one tls certificate is enabled on the nginx server. OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("ENDPOINT").build(); Response response = client.newCall(request).execute(); System.out.println(response.body().string()); Activating a site with a different certificate causes nginx to enable SNI. That apparently breaks both on Oracle Java 7 as well as OpenJDK 7. Exception in thread "main" java.net