黑莓用户代理和HTTPS URL重定向 [英] Blackberry User-Agent and https Redirect url

查看:165
本文介绍了黑莓用户代理和HTTPS URL重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图访​​问通过输入浏览器中的价值HTTPS连接,它似乎做工精细并重定向我预期的页/输出。但是,当我使用code尝试一样,我无法得到的结果。我尝试设置用户代理为(Mozilla的/ 5.0(黑莓手机; U;黑莓9800; EN-GB)为AppleWebKit / 534.1 +(KHTML,例如Gecko)版本/ 6.0.0.141移动版Safari / 534.1 +)。但没有运气。我越来越受信任的连接警告,当我点击继续,我得到响应code 302.How我可以实现安全连接证书禁用可信连接的警报。

我习惯httpsconnection打开URL返回响应code 302.Again我

检查

 如果(RC == HttpConnection.HTTP_TEMP_REDIRECT
            || RC == HttpConnection.HTTP_MOVED_TEMP
            || RC == HttpConnection.HTTP_MOVED_PERM){
    。字符串位置= conn.getHeaderField(位置)修剪();
    的System.out.println(位置========+位置);
    尝试{
        URL =位置;
        newhttpConn =(HttpConnection的)Connector.open(URL,Connector.READ_WRITE);
        newhttpConn.setRequestMethod(HttpConnection.POST);
        newhttpConn.setRequestProperty(用户代理,
                System.getProperty(browser.useragent));
    }赶上(例外五){
        的System.out.println(e.toString());
    }

但是没有用我从重定向URL得到相同的302。

编辑:

另外请给一些想法,让相当于给了HTTPClient在HTTPSConnection工作的功能。我怎样才能获得这些功能。如果没有可能使用HttpClient的黑莓那么,我怎么可以利用黑莓https连接相当于Httpcleint(或)使用HTTPS连接获得自动重定向?

在connector.open(URL)excutes我得到这样

  SSL: - > CH
SSL:或其可-SH
SSL:< -SC
SSL:< -SHD
TLS: - > CKE
SSL: - > CCS
TLS: - >˚F
TLS:LT-F

在输出控制台,然后错误的反应显示出来。


解决方案

  

我越来越受信任的连接警告,当我点击继续,我得到响应code 302。


这是一个完全预期的行为。

302指所请求的资源是其他的URI。换句话说服务器指示您执行重定向。您应该调查的连接头和一个名为位置,你会发现一个新的URI继续进行。关闭/完成你当前的连接,并开始为刚重定向URI一个新的。

更新

通常良好的服务器使用HTTP响应302成功POST之后。这是一个已知的邮政/重定向/获取模式以prevent用户张贴在浏览器页面刷新相同的数据twise(用户可以在$桌面浏览器p $ PSS F5)。所以,如果你是通过POST访问该网页是专门为通常的浏览器,那么这可能仅仅意味着你的职位是成功的,你不需要执行重定向请求。至少,如果你需要一些结果评估的响应,那么使用POST没有自动跳转,这个时候使用GET。

I tried to access a HTTPS connection by entering the value in browser, it seems to work fine and redirects me to expected page/output. But when I tried the same using the code, I am unable to get the result. I tried of setting the UserAgent as (Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en-GB) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.141 Mobile Safari/534.1+). But no luck. I am getting trusted connection alert, when i click continue i get response code 302.How can i implement secure connection certificate to disable trusted connection alert.

I am used to httpsconnection to open url it returns the response code 302.Again i checked with

if (rc == HttpConnection.HTTP_TEMP_REDIRECT
            || rc == HttpConnection.HTTP_MOVED_TEMP
            || rc == HttpConnection.HTTP_MOVED_PERM) {
    String location = conn.getHeaderField("location").trim();
    System.out.println("location========"+location);
    try {
        Url = location;
        newhttpConn = (HttpConnection) Connector.open(Url, Connector.READ_WRITE);
        newhttpConn.setRequestMethod(HttpConnection.POST);
        newhttpConn.setRequestProperty("User-Agent", 
                System.getProperty("browser.useragent"));
    } catch (Exception e) {                               
        System.out.println( e.toString());            
    }

But no use i am getting same 302 from redirect url.

EDITED:

Also please give some ideas to get the functions equivalent to HTTPClient to be work in HTTPSConnection. How can i get those functionalities. If there is no possibility to use Httpclient in blackberry then how can i utilize Blackberry https connection equivalent to Httpcleint (or) to get the automatic redirect using HTTPS Connection?

When connector.open(url) excutes i am getting like this

SSL:->CH
SSL:<-SH
SSL:<-SC
SSL:<-SHD
TLS:->CKE
SSL:->CCS
TLS:->F
TLS:<-F

in output console then wrong response displayed.

解决方案

I am getting trusted connection alert, when i click continue i get response code 302.

This is a fully expected behaviour.

302 means the requested resource is on some other URI. In other words server instructs you to execute a redirect. You should investigate connection headers and in the one named "Location" you will find a new URI to continue with. Close/finalize you current connection and start a new one for the just got redirect URI.

UPDATE:

Usually good servers respond with HTTP 302 after a successful POST. This is a known Post/Redirect/Get pattern to prevent users from posting the same data twise on browser page refresh (user may press F5 in a desktop browser). So if the page you are accessing via POST is designed for usual browsers, then this may just mean your POST was successful and you don't need to execute a redirecting request. At least, if you need the response for some result evaluation then don't redirect using a POST, this time use a GET.

这篇关于黑莓用户代理和HTTPS URL重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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