2016-05-26 46 views
0
URL oracle = new URL("hurlAddress/dinfo.cgi"); 
    BufferedReader in = new BufferedReader(
    new InputStreamReader(oracle.openStream())); 

    String inputLine; 
    while ((inputLine = in.readLine()) != null) 
     System.out.println(inputLine); 
    in.close(); 

我得到不能夠在Java中讀取URL內容

<html> 
<head> 
    <!-- RUI RC=100 --> 
    <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> 
    <title>Don't open this page!</title> 
</head> 
<body bgcolor="#C0C0C0"> 
    <center> 
    <table border="0" cellpadding="0" cellspacing="4" width="400"> 
    <tr><td align="center" valign="top" width="48"> 
      <img src="en/media/ss_wrn.gif" border="0" width=32 height=32> 
     </td> 
     <td> 
      <font size="4" face="Helvetica,Arial"> 
      <b>User information is disabled.</b><br> 
      This operation cannot be accepted. User certification is invalid or date expired.<br> 
      Update page.<br> 
      </font> 
     </td> 
    </tr> 
    <tr><td></td> 
     <td align="right"> 
      <a href="./_top.htm" target="_top"><img src="en/media/b_ok.gif" border="0" alt="OK" title="OK"></a> 
     </td> 
    </tr> 
    </table> 
    </center> 
</body> 

我期待

<html> 

<head> 
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> 
<title>Remote UI:Device Information</title> 
</head> 

<body bgcolor="white" link="blue" alink="red" vlink="blue"> 
<a name="page_top"></a> 
<form> 

<SCRIPT LANGUAGE="JavaScript"> 
var has_fax = false; // true or false 
var Fax_Type = "0"; // 0(None),1(PSTN),2(PSTNx2),3(ISDN) 
var has_send =true; // has send 
var is_oem = false; 
</SCRIPT> 

<SCRIPT LANGUAGE="JavaScript"> 
function reload_device(){ 
var cgi_str = "./dinfo.cgi?"; 

// for Expire Cache!! 
var now_time = new Date(); 
cgi_str += "Dummy=" + now_time.getTime(); 

document.location.href = cgi_str; 
} 
</SCRIPT> 

<table border="0" cellpadding="0" cellspacing="2" width="100%"> 
<tr> 
<td valign="middle"><font size="4" color="#000066"><b><table border="0" cellpadding="0" cellspacing="2"> 
<tr> 
<td rowspan="2" nowrap><img src="en/media/imgs030.gif"></td> 
<td nowrap><font face="Helvetica,Arial" size="4" color="#000066"><b>slq29986</b></font></td> 
</tr> 
<tr> 
<td nowrap><font size="2">iR5570</font></td> 
</tr> 
</table></b></font></td> 
<td valign="middle" width="70" align="right"><font size="4" color="black"><b><a href="javascript:reload_device()" target="_self"><img src="en/media/bh_updt.gif" width="28" height="28" border="0" alt="Update" title="Update"></a></b></font></td> 
</tr> 
</table> 
<hr noshade size="2"> 
<table border="0" cellpadding="0" cellspacing="4" width="100%"> 
<tr> 
<td align="left"><font size="1">&nbsp;Last Updated :05/26/2016 19:30:54</font></td> 
</tr> 
</table><table border="0" cellspacing="0" cellpadding="2" width="100%"> 
<tr height="26"> 
<td bgcolor="#000066" height="26"><font color="white" face="Helvetica,Arial"><b>&nbsp;Device Information</b></font></td> 
</tr> 
</table><table border="0" cellspacing="2" cellpadding="2" width="100%"> 

<SCRIPT LANGUAGE="JavaScript"> 
if(is_oem == false) 
{ 
document.write('<tr>'); 
document.write('<td width="3%"></td>'); 
document.write('<td width="40%"><font face="Helvetica,Arial" size="2">Manufacturer :</font></td>'); 
document.write('<td><font size="4">CANON INC</font></td>'); 
document.write('</tr>'); 
} 
</SCRIPT> 

<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Device Name :</font></td> 
<td><font size="4">slq29986</font></td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Location :</font></td> 
<td><font size="4">MESAAS</font></td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Product Name : </font></td> 
<td>iR5570</td> 
</tr> 
<tr> 
<td colspan="3"><hr size="1"></td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Serial Number :</font></td> 
<td>SLQ29986</td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Main Board Version :</font></td> 
<td>1</td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Controller Version :</font></td> 
<td>3604.838.3201</td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Scanner Version :</font></td> 
<td>401.100</td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Finisher Version :</font></td> 
<td>801</td> 
</tr> 

<SCRIPT LANGUAGE="JavaScript"> 
if(has_send == true) 
{ 
document.write('<tr>'); 
document.write('<td colspan="3">'); 
document.write('<hr size="1">'); 
document.write('</td>'); 
document.write('</tr>'); 

document.write('<tr>'); 
document.write('<td width="3%"></td>'); 
document.write('<td width="40%"><font face="Helvetica,Arial" size="2">Receive E-mail Address :</font></td>'); 
document.write('<td>[email protected]</td>'); 
document.write('</tr>'); 
} 
</SCRIPT> 

<SCRIPT LANGUAGE="JavaScript"> 
if(has_fax == true) 
{ 
    document.write('<tr>'); 
    document.write('<td colspan="3">'); 
    document.write('<hr size="1">'); 
    document.write('</td>'); 
    document.write('</tr>'); 

    document.write('<tr>'); 
    document.write('<td width="3%"></td>'); 
    document.write('<td width="40%"><font face="Helvetica,Arial" size="2">Telephone Number :</font></td>'); 
    document.write('<td></td>'); 
    document.write('</tr>'); 

    if(Fax_Type == "3") 
    { 
    document.write('<tr>'); 
    document.write('<td width="3%"></td>'); 
    document.write('<td width="40%"><font face="Helvetica,Arial" size="2">Subaddress :</font></td>'); 
    document.write('<td></td>'); 
    document.write('</tr>'); 
    } 
} 
</SCRIPT> 

<tr> 
<td colspan="3"> 
<hr size="1"> 
</td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">System Manager :</font></td> 
<td>MESAAS</td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Contact Information :</font></td> 
<td></td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">E-mail Address :</font></td> 
<td><a href="mailto:"></a></td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Support :</font></td> 
<td><a href="" target="_top"></a></td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Administrator Comment (E-mail) :</font></td> 
<td></td> 
</tr> 

<tr> 
<td colspan="3"> 
<hr size="1"> 
</td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Contact Person :</font></td> 
<td></td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Phone :</font></td> 
<td></td> 
</tr> 
<tr> 
<td width="3%"></td> 
<td width="40%"><font face="Helvetica,Arial" size="2">Comment (E-mail) :</font></td> 
<td></td> 
</tr> 

</table> 
<p> 
<hr size="2"> 
<table border="0" cellspacing="0" cellpadding="0" width="100%"> 
<tr> 
<td valign="bottom"><a href="javascript:scrollTo(0,0);"><img src="en/media/ba_ptp.gif" border="0" hspace="2" vspace="2" alt="Back to the Top on This Page" title="Back to the Top on This Page"></a></td> 
</tr> 
</table> 
</form> 
</body> 

</html> 
+1

您可以嘗試在瀏覽器中捕獲獲取請求,並在java請求中添加必要的標頭。 – amitmah

+1

位於128.59.88.252的Web服務器正在檢測您是Java應用程序而不是Web瀏覽器。網絡服務器將您引導至入侵者登錄頁面。您必須執行amitmah在其評論中所建議的內容,並使您的Java應用程序看起來像瀏覽器到Web服務器。請注意,amitmah暗示的是**不道德**使用網站。 –

+0

謝謝,我捕獲了這個請求,並且發現我必須使用HttpURLConnection連接; connection.setRequestProperty(「Cookie」,「iR = 7472571」); – telebog

回答

0

感謝amitmah和吉爾伯特勒布朗我安裝 是HttpFox插件在Firefox和我注意到,我需要設置一個cookie

URL url = new URL("urlAddress/dinfo.cgi"); 
HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 
connection.setRequestProperty("Cookie", "iR=7472571"); 

try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))){ 
      StringBuilder builder = new StringBuilder(); 
      int cp; 

      while ((cp = in.read()) != -1) { 
       builder.append((char) cp); 
      } 

      return builder.toString(); 
} 

在瀏覽器中,如果我訪問第一個urlAddress,則設置此cookie。如果我嘗試直接訪問urlAddress/dinfo.cgi,則會得到相同的「用戶信息已禁用...」響應。