HTT presponse code 302 [英] HttpResponse code 302

查看:742
本文介绍了HTT presponse code 302的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用模拟器BB 8900我试图连接到URL并获得响应code 302.What意思呢?
 这里是我的code片断:

 进口javax.microedition.io.Connector;
进口javax.microedition.io.HttpConnection;
.....
连接=(HttpConnection的)Connector.open(URL);
响应code = connection.getResponse code();


解决方案

一个HTTP 302是一个临时重定向 。你需要处理它。

按照标准,如果你得到一个302响应,响应将包含重定向一个位置头字段:

 客户端请求:
GET /index.html HTTP / 1.1
主持人:www.example.com服务器响应:
HTTP / 1.1 302找到
地点:http://www.redirected-address.example.com/

您需要提取从响应新的URL。 (使用<一个href=\"http://java.sun.com/javame/reference/apis/jsr219/javax/microedition/io/HttpConnection.html#getHeaderField%28java.lang.String%29\"><$c$c>getHeaderField(\"Location\")去做这个)。然后你得到了新的URL,执行同样的方法。

另外两点:


  1. 由于这是一个临时重定向,你不能存储这个新的URL。你应该继续使用旧的,如果它返回一个302,然后使用任何URL在位置。


  2. 如果你不执行一个GET或HEAD,你不应该做自动重定向。而要求用户干预。 的RFC需要此


I am using simulator BB 8900. I am trying to connect to url and get response code 302.What does it mean? Here is my code snippet:

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
.....
connection = (HttpConnection)Connector.open(url);
responseCode = connection.getResponseCode();

解决方案

An HTTP 302 is a 'temporary redirect'. You need to handle it.

As per the standard, if you get a 302 response, the response will contain a 'Location' header field with the redirect:

Client request:
GET /index.html HTTP/1.1
Host: www.example.com

Server response:
HTTP/1.1 302 Found
Location: http://www.redirected-address.example.com/

You need to extract the new URL from the response. (Use getHeaderField("Location") to do this). Then execute the same method on the new URL you got.

Two other points:

  1. Since this is a 'temporary' redirect, you cannot store this new URL. You should keep using the old one, and if it returns a 302, then use whatever URL is in 'Location'.

  2. If you are not executing a GET or HEAD, you shouldn't do the redirect automatically. Instead ask for user intervention. The RFC requires this.

这篇关于HTT presponse code 302的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆