本人准备用海词的Web API接口http://dict.cn/mini.php?q=word 写一个本地客服端查词程序
用httpclient3.1访问后得到的是:
Define book : [buk]
正在加载<book>的翻译解释
例句与用法:
正在加载<book>的相关例句与用法
词形变化:
正在加载<book>的词形变化
加入生词本 看详细解释
而我想得到的是从浏览器直接打开的效果 :
Define book : [buk]
n.书, 本子
v.预订, 记录在案
例句与用法:
1. He was booked by the referee for foul play.
他因为动作犯规而被裁判记下姓名。
2. He's always careful to do things by the book.
他总是小心翼翼地按规章办事。
3. You'll have to book early if you want to see that fashion show.
你要想看那场时装表演的话,就得早点儿定座位。
4. He was booked on a charge of speeding.
他因超速开车而被记录在案。
词形变化:
名词:booker 动词过去式:booked 动词过去分词:booked 动词现在分词:booking 动词第三人称单数:books
加入生词本 看详细解释
请问在j2se中如何实现?
附代码:
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();