Blackberry User-Agent and https Redirect url

醉酒当歌 提交于 2019-12-25 04:03:39

问题


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.


回答1:


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://stackoverflow.com/questions/8094615/blackberry-user-agent-and-https-redirect-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!