English 中文(简体)
在 Java,我是如何下载一个被改用的网页的?
原标题:In Java, how I download a page that was redirected?
  • 时间:2011-05-02 19:27:38
  •  标签:
  • java

我制造了一个网络拖网,有几页改用。 我怎么回过原来的网页?

在一些地点,如Xtema.com.br,我可以采用HttpURLConnection等级,采用“Location”方法,但在其他情况下,如签证.com.br,改头使用javascript或另一种方式,这种方法的回报无效。

总是有某种方式来接上该网页,然后又转方向。 没有任何改头的原始网页并不重要。

• 感谢和骚扰坏官。

EDIT:利用httpConn.setInstance FollowRedirects(true)跟踪Redirections,并将URL与httpConn.getURL合用。

1 The httpConn.getURL only will re-directed page if I calls httpConn.getDate before. 如果我这样做的话,它将在重新定向之前归还原来的URL。

2: Some sites like visa.com.br get the answer 200, but if I open then in the web browser, I see another page. Eg.: my program - visa.com.br - answer 200 (no redirections) web broser - visa.com.br/go/principal.aspx - html code different of the version that i get in my program

最佳回答

使用<代码>HttpURLConnection, 依附后改头。

如果你想看到重新定位的URL,你必须:

httpConn.setInstanceFollowRedirects( false );
httpConn.connect(); 
int responseCode = httpConn.getResponseCode();
while ((responseCode / 100) == 3) { /* codes 3XX are redirections */
   String newLocationHeader = httpConn.getHeaderField( "Location" );
   /* open a new connection and get the content for the URL newLocationHeader */
   /* ... */
   responseCode = httpConn.getResponseCode();
   /* do it until you get some code that is not a redirection */
}
问题回答

你们可以很容易地得到 j印的改头脑。 而《人权法案》的重新定位则通过<代码>的违约处理。 HttpURLConnection 。 您可以做的是,查找几个关键词的网页内容:

  • the meta refresh tag
  • document.location=, window.location= and both with .href=

但这不能保证任何东西。 人们可能把 j印功能从外部垃圾档案中挑出来,而你则非常需要腾出资源和 par,你们不愿意这样做。

我最后使用。ache s HTTP的客户。 还有一个选择。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签