怎么判断旺旺是否在线 不要那个返回图片的代码,要其他的.
求高手指教。感激不尽、、、、
求高手指教。感激不尽、、、、
解决方案 »
- repaint方法是不是与paint()方法是成对调用的,固定的?
- 请教基本语法this.class.getClassLoader()怎么理解?
- 关于java里GC的问题。
- 如何比较两张照片是否相同??
- 谁有<core java>代码发给我
- 怎么在servlet里取得远程主机上的一幅图片?比如sohu网站上的一幅图片??
- 终于能发200分的帖子了,给大家散点分,顺便问个弱弱的问题。
- StringBuffer类的 delete方法的参数问题?
- 谁在啃java编程思想
- 请教高手:是否使用PowerJ开发过JAVA应用? 效果如何?
- 多线程协作 CyclicBarrier 如何<b>重复<b>使用
- 求解一个for语句的意思
import java.io.IOException;import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;public class TaobaoT { public static void main(String[] args) throws IOException {
String url = "http://scs1.sh1.china.alibaba.com/online.atc?v=1&uid=wangbinbinda&s=2"; HttpClient client = new HttpClient();
GetMethod method = new GetMethod(url); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
method.setFollowRedirects(false);//取消自动转向
try {
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
Header[] ss = method.getResponseHeaders();//debug此处,可以看到Location的目标url
//byte[] responseBody = method.getResponseBody();
//System.out.println(new String(responseBody));
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
method.releaseConnection();
}
}}
Request Method:GET
Status Code:302 Found
Request Headers
Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:ali_beacon_id=124.42.13.234.1299463958610.6; cna=Fi37Bc+XbBsCAeoNKnxWMi6L; ali_apache_id=124.42.13.234.08361963963860.3
Host:scs1.sh1.china.alibaba.com
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13
Query String Parameters
v:1
uid:wangbinbinda
s:2
Response Headers
Cache-Control:no-cache
Connection:close
Content-Length:0
Content-Type:text/html
Date:Tue, 15 Mar 2011 03:15:29 GMT
Location:http://img.im.alisoft.com/actions/wbtx/alitalk/92/notuser.gif
Server:Apache/2.2.9 (Unix)
URL url = null;
HttpURLConnection http = null;
InputStream in = null;
try {
url = new URL(
"http://amos1.taobao.com/muliuserstatus.aw?beginnum=0&site=cntaobao&uids=wangbinbinda");
http = (HttpURLConnection) url.openConnection();
in = http.getInputStream();
int len = 0;
byte[] buffer = new byte[20];
String temp = "";
while ((len = in.read(buffer)) != -1) {
temp = temp + new String(buffer, 0, len, "utf-8");
}
int i = Integer.parseInt(temp.substring(temp.length() - 2, temp
.length() - 1));
if (i == 0) {
return false;
} else {
return true;
}
} catch (Exception e) {
System.out.println(e.getMessage());
return false;
} finally {
if (in != null) {
try {
in.close();
http.disconnect();
} catch (IOException ex) {
System.out.println(ex);
}
}
}
}
在线返回true 不在线返回false