How to follow a "page auto-redirection" to get the response code?
blackberry, blackberry-jde, blackberry-os-v4.5, java-me, rim-4.5
Solution
I found the solution, Here it is for those who are interested:
int resCode;
String location = "http://company.com/temp1.aspx";
while (true) {
HttpConnection connection = (HttpConnection) Connector.open(location + ";deviceside=true");
connection.setRequestMethod(HttpConnection.GET);
connection.setRequestProperty(HttpHeaders.HEADER_CONNECTION, "close");
connection.setRequestProperty(HttpHeaders.HEADER_CONTENT_LENGTH, "0");
resCode = connection.getResponseCode();
if( resCode == HttpConnection.HTTP_TEMP_REDIRECT
|| resCode == HttpConnection.HTTP_MOVED_TEMP
|| resCode == HttpConnection.HTTP_MOVED_PERM ) {
location = connection.getHeaderField("location").trim();
} else {
resCode = connection.getResponseCode();
break;
}
}
Problem
I use the following code to get the returned response code of an aspx page ``` HttpConnection connection = (HttpConnection) Connector.open("http://company.com/temp1.aspx" + ";deviceside=true"); connection.setRequestMethod(HttpConnection.GET); connection.setRequestProperty(HttpHeaders.HEADER_CONNECTION, "close"); connection.setRequestProperty(HttpHeaders.HEADER_CONTENT_LENGTH, "0"); int resCode = connection.getResponseCode(); ``` It works fine. But what if the link "http://company.com/temp1.aspx" auto-redirects to another page; assume "http://noncompany.com/temp2.aspx" ? How can i get the response code which is returned from the second link (the one which the first link redirected to) ? Is there something like "follow redirection" to get the new response of the page whom was auto-redirected to ? Thanks in advance.