13,100
社区成员
发帖
与我相关
我的任务
分享
public static String getHeaderFieldNewURL(String url) throws Exception{
try {
HttpConnection conn = (HttpConnection) Connector.open(url,Connector.READ_WRITE);
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
conn.setRequestMethod(HttpConnection.POST);
//conn.setFollowRedirects();
int responseCode =conn.getResponseCode();//
//302 Redirect
if(responseCode==HttpConnection.HTTP_MOVED_TEMP){
String newUrl =conn.getHeaderField("Location");//new_uri is null on some devices
conn.close();
return newUrl;
}else{
conn.close();
return "";
}
} catch (Exception e) {
//throw new Exception("Response status not OK");
e.printStackTrace();
return null ;
}