質問

私は、次のコードを取得し、返された応答コードのaspxページ

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();

です。その場合はリンク"http://company.com/temp1.aspx"オートリダイレクトを別のページい"http://noncompany.com/temp2.aspx"?かの応答コードされたものではなく、からのリンクの最初のリンクにリダイレクト)?あのようなもの"にリダイレクト"の新しい応答のページ名のオートリダイレクトす。

よろしくお願いします。

役に立ちましたか?

解決

また、ソリューション こちらではの興味のある:

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;
     }
}

他のヒント

必要なコードおHttpConnection内するループ以下のHTTP redirectionsに基づく応答コードです。

のHTTPヘッダの"場所"の回答がっていただけるように新しいホストもで置換することができ、全体のURL)

HttpConnection.HTTP_MOVED_TEMPHttpConnection.HTTP_MOVED_PERM の応答コードがリダイレクト.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top