67,514
社区成员
发帖
与我相关
我的任务
分享
public class Test {
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost("bill.finance.sina.com.cn", 80,
"http");
GetMethod mt = new GetMethod("/bill/detail.php?stock_code=sh601699");
mt.addRequestHeader("Content-type", "text/xml; charset=GB2312");
mt.addRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");
client.executeMethod(mt);
byte[] outBytes = new byte[1024];//只取一个字节做测试
Inflater inflater = new Inflater(true);
inflater.setInput(mt.getResponseBody());
try {
inflater.inflate(outBytes, 0, outBytes.length);
System.out.println(new String(outBytes));
} catch (DataFormatException e) {
e.printStackTrace();
}
}
}
HttpResponse rsp = client.execute(target, req, null);
entity = rsp.getEntity();
InflaterInputStream encoded = new InflaterInputStream(entity.getContent());
final ByteArrayOutputStream decoded = new ByteArrayOutputStream ();
final byte buffer[] = new byte[1024];
int length;
while((length = encoded.read (buffer)) != -1)
{
decoded.write (buffer, 0, length);
}
// closing
encoded.close ();
decoded.close ();
if (entity != null) {
System.out.println(new String (decoded.toByteArray(),"gb2312"));//EntityUtils.toString(rsp.getEntity()));
}
Exception in thread "main" java.util.zip.ZipException: unknown compression method
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:140)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
at ClientExecuteDirect.main(ClientExecuteDirect.java:112)