1
我正在使用一個應用程序,它連接了url並從頁面檢索數據。不幸的是,它沒有到達我感興趣的頁面。將url重定向到java代碼中的新url
如何通過java代碼中的GET方法將其重定向到期望的頁面?
輸出 「的ReadLine」 方法顯示了我它擊中/MRcgi/MRlogin.pl,但我希望去不同的網址
O/P
<TITLE> Service Core</TITLE>
<script type="text/javascript">
var replace_function = function() {
window.location.replace('/MRcgi/MRlogin.pl?USER=***p&PASSWORD=webauth&PROJECTID=-1');
}
代碼 -
URL obj = new URL(url);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
String userPassword = "*****";
String encoding = new String(
org.apache.commons.codec.binary.Base64
.encodeBase64(org.apache.commons.codec.binary.StringUtils
.getBytesUtf8(userPassword)));
((HttpURLConnection) con).setRequestMethod("GET");
con.setRequestProperty("Content-Type", "text/plain");
con.setRequestProperty("charset", "UTF-8");
con.setRequestProperty("Authorization", "Basic " + encoding);
// Send post request
///
// con.setDoOutput(false);
/* DataOutputStream wr = new DataOutputStream(con.getOutputStream());
System.out.println("1111" +wr);
wr.writeBytes(urlParameters);
wr.flush();
wr.close();*/
int responseCode = ((HttpURLConnection) con).getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + con);
//System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
//window.location.replace("");
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
//con.
String inputLine;
StringBuffer response = new StringBuffer();
System.out.println("-----" + in.readLine());
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
//response.append(inputLine);
}
in.close();
沒有它不適合我。我無法運行「httpclient.execute(httpget);」 。我收到一個錯誤 - 處理請求到{s}時發生I/O異常(java.net.SocketException) - > https://help.com:443:來自SOCKS服務器的格式錯誤的回覆 Jun 21,2017 11:33 :上午07點org.apache.http.impl.execchain.RetryExec執行 – Raz