2

私は次の方法を持っています:

public void GetBackground(final int width, final int height, final Long ifModifiedSince,
        final GetBackgroundListener listener)
{
    new Thread(new Runnable()
    {
        public void run()
        {
            try {
                String urlString = serviceUri + "/DownloadBackground?width=" + width
                        + "&height=" + height;
                URL url = new URL(urlString);
                HttpURLConnection connection = (HttpURLConnection)url.openConnection();
                if (ifModifiedSince != null) {
                    Log.d(TAG, "Background last modified: " + ifModifiedSince);
                    connection.setIfModifiedSince(ifModifiedSince);
                }
                InputStream stream = (InputStream)connection.getContent();
                if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
                    listener.onNotModified();
                    Log.d(TAG, "Background not modified");
                } else {
                    Bitmap background = BitmapFactory.decodeStream(stream);
                    listener.onSuccess(background, connection.getLastModified());
                    Log.d(TAG, "New background");
                }
            } catch (Exception e) {
                listener.onError(e);
            }
        }
    }).start();
}

Android 2.2 では、次のパッケージが生成されます。

GET /QurrentService.svc/DownloadBackground?width=480&height=480 HTTP/1.1
if-modified-since: Thu, 13 Dec 2012 09:11:23 GMT
User-Agent: Dalvik/1.2.0 (Linux; U; Android 2.2; sdk Build/FRF91)
Host: qurrentfeed1.1.aliencms.nl
Connection: Keep-Alive

Android 4.1 の場合:

GET /QurrentService.svc/DownloadBackground?width=800&height=800 HTTP/1.1
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.1.2; sdk Build/MASTER)
Host: qurrentfeed1.1.aliencms.nl
Connection: Keep-Alive
Accept-Encoding: gzip
If-Modified-Since: Thu, 13 Dec 2012 09:11:23 UTC

If-modified-since 日付を UTC 時間として送信できるかどうかはわかりませんが、サーバーは日付の解析に失敗します。HttpURLConnection に GMT 形式を強制的に生成させる方法はありますか? または、このようにヘッダーを手動で設定する必要がありますか?

String ifModifiedSinceString = DateUtils.formatDate(new Date(ifModifiedSince), "EEE, d MMM yyyy HH:mm:ss 'GMT'");
connection.addRequestProperty("If-Modified-Since", ifModifiedSinceString);
4

0 に答える 0