I'm trying to use Java's HttpURLConnection to do a “conditional get”, but I never get a 304 status code

后端 未结 2 810
别跟我提以往
别跟我提以往 2020-12-17 02:08

Here is my code:

    final HttpURLConnection conn = (HttpURLConnection) sourceURL.openConnection();
    if (cachedPage != null) {
        if (cachedPage.eTag         


        
2条回答
  •  萌比男神i
    2020-12-17 02:53

    Or shorter :)

    Just try set connection timeout other than 0.

    conn.setConnectionTimeout( 3000);
    

    Do it after .openConnection()

    final HttpURLConnection conn = (HttpURLConnection) sourceURL.openConnection();
    conn.setConnectionTimeout( 3000);
    

    If not set also readTimeout other than 0.

    conn.setReadTimeout( 3000);
    

提交回复
热议问题