Nokia S60如何处理302 HTTP状态[J2ME]

news/2024/7/5 9:38:24

[j2me] Nokia S60如何处理302 HTTP状态

历史

Version

Date

Creator

Description

1.0.0.1

2006-7-24

郑昀

第一稿

 

1 Nokia S60如何处理302HTTP状态

 

HttpConnection/302/ HTTP_TEMP_REDIRECT

关键词

详细描述

当用HttpConnection读取远端数据,而远端返回状态码302表示重定向时,继续调用openInputStream来读取输入流将会导致程序崩溃。

 

此种现象发生在以下机型:

Nokia N90/

6600/6630/6680

 

N70不会崩溃但也不会正常运行。

根据协议规定,此时的Location头域中保存了你应该重新请求的地址。

请看

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.3 来了解更多关于"302 Found"

 

也就是说,此时用HttpConnection.getHeaderField("Location")来得到具体的跳转url,然后重新向新地址发起请求。

 

代码示范:

 

private HttpConnection open(String url) throws IOException {

HttpConnection c;

int status = -1;

 

// Open the connection and check for redirects

while (true) {

c = (HttpConnection) Connector.open(url);

 

// Get the status code,

// causing the connection to be made

status = c.getResponseCode();

 

if ((status == HttpConnection.HTTP_TEMP_REDIRECT)

|| (status == HttpConnection.HTTP_MOVED_TEMP)

|| (status == HttpConnection.HTTP_MOVED_PERM)) {

 

// Get the new location and close the connection

url = c.getHeaderField("location");

c.close();

} else {

break;

}

}

 

// Only HTTP_OK (200) means the content is returned.

if (status != HttpConnection.HTTP_OK) {

c.close();

throw new IOException("Response status not OK");

}

return c;

}

 

 

参考资料1RFC2616

10.3.3 302 Found

The requested resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only cacheable if indicated by a Cache-Control or Expires header field.

The temporary URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).

If the 302 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.

      Note: RFC 1945 and RFC 2068 specify that the client is not allowed
      to change the method on the redirected request.  However, most
      existing user agent implementations treat 302 as if it were a 303
      response, performing a GET on the Location field-value regardless
      of the original request method. The status codes 303 and 307 have
      been added for servers that wish to make unambiguously clear which
      kind of reaction is expected of the client.

 

参考资料2Nokia Forum

KVM crashes when reading content with HTTP "302 Found" response on N90 and 6680





http://www.niftyadmin.cn/n/3648135.html

相关文章

docker 容器共享数据_如何在Docker容器之间共享数据

docker 容器共享数据介绍 (Introduction) Docker is a popular containerization tool used to provide software applications with a filesystem that contains everything they need to run. Using Docker containers ensures that the software will behave the same way r…

SpringBoot的官方英文介绍(中文译本)

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". 翻译:SpringBoot可以很简单的创建一个基于项目的单机版,生产环境水平的Spring框架,从而让你的项目运行…

X Window研究笔记(20)

X Window研究笔记(20)转载时请注明出处和作者联系方式作者联系方式:李先静 20.X Window资源管理在X Window中,资源是一个广泛使用的概念。它包括图片、光标和窗口等对象,可以是内置的,也可以是注册的。每个资源都有一个ID&#xf…

SVN项目更新失败被锁定的解决方案

相关网址: 标题:svn更新项目提示该项目已锁定,svn“清理”解决问题 网址:https://blog.csdn.net/strwangfan/article/details/78748393 标题:SVN被锁定解决办法 网址:https://blog.csdn.net/strwangfan…

通过DigitalOcean Kubernetes扩展应用程序以实现增长

视频 (Video) 介绍 (Introduction) Effectively scaling your SaaS is imperative to business growth. Once you have built your application, it’s time to prepare for growth in usage. When to scale up? When to scale down? What metric to track for scaling? How…

X Window研究笔记(21)

X Window研究笔记(21)转载时请注明出处和作者联系方式作者联系方式:李先静 21.X Window 字符串与AtomAtom是X Window中的一大特色,不把它弄清楚,可能会对阅读其它代码形成障碍。X Window把常用的字串用一个hash表来管理,并给这些字…

react 实现滚动加载_如何在React中实现平滑滚动

react 实现滚动加载介绍 (Introduction) Smooth scrolling is when instead of clicking on a button and being instantly taken to a different part of the same page, the user is navigated there via a scroll animation. It’s one of those subtle UI features on a si…

jsp、freemarker、velocity、thymeleaf模板引擎优缺点

1、概述 在java领域,表现层技术主要有三种, (1)jsp; (2)freemarker; (3)velocity; (4)thymeleaf; 2、jsp 优点: 1、功能强大,可…