有没有办法在 java 中通过 HTTP 进行 get & put 调用?我还需要自动化任何用户输入,例如目标网页上的按钮单击(任何网页,不仅仅是雅虎财经)
我尝试使用 apache commons library & 不能完全破解它:
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
public class Fin {
/**
* @param args
*/
public static void main(String[] args) {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://finance.yahoo.com");
try {
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
} catch (Exception e) {
e.printStackTrace();
} finally {
httpget.releaseConnection();
}
}
}
我不断收到“java.net.ConnectException:连接被拒绝”,尽管我可以在浏览器中看到它。