日期:2014-05-17 浏览次数:20767 次
import java.io.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
class HC_t{
public static void main(String[] args) {
System.out.println("qgb");
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod("http://dict.cn/mini.php?q=book");
getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler());
try {
int statusCode = httpClient.executeMethod(getMethod);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + getMethod.getStatusLine());
}
byte[] responseBody = getMethod.getResponseBody();
FileOutputStream fos=new FileOutputStream("1.htm");
fos.write(responseBody);
//System.out.println(new String(responseBody));
}
catch (HttpException e) {
System.out.println("Please check your provided http address!");
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();