怎么判断旺旺是否在线 怎么判断旺旺是否在线 不要那个返回图片的代码,要其他的.求高手指教。感激不尽、、、、 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是怎么判断旺旺是否在线,有这样一个链接 http://scs1.sh1.china.alibaba.com/online.atc?v=1&uid=wangbinbinda&s=2可以转向在线和不在线的图片地址。如果是获得在线和不在线的图片怎么解析··我用 HttpURLConnection读取到的输入流是一个图片的但全是乱码应该怎么解析。还有一个方法是得到他这个地址转向的地址可以判断是转向在线图片或不在线图片地址,问题是不知道怎么获得转向后的地址 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 URL:http://scs1.sh1.china.alibaba.com/online.atc?v=1&uid=wangbinbinda&s=2Request Method:GETStatus Code:302 FoundRequest HeadersAccept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3Accept-Encoding:gzip,deflate,sdchAccept-Language:zh-CN,zh;q=0.8Cache-Control:max-age=0Connection:keep-aliveCookie:ali_beacon_id=124.42.13.234.1299463958610.6; cna=Fi37Bc+XbBsCAeoNKnxWMi6L; ali_apache_id=124.42.13.234.08361963963860.3Host:scs1.sh1.china.alibaba.comUser-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.13Query String Parametersv:1uid:wangbinbindas:2Response HeadersCache-Control:no-cacheConnection:closeContent-Length:0Content-Type:text/htmlDate:Tue, 15 Mar 2011 03:15:29 GMTLocation:http://img.im.alisoft.com/actions/wbtx/alitalk/92/notuser.gifServer:Apache/2.2.9 (Unix) public boolean checkWangWang() { 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 char.toString()乱码怎么解决? 数据库提取数据问题~~~新人求助! java程序不用头文件的原理是什么? 关于数组插入元素的问题 String sb=new String();和sb=sb+'*';的一些理解 怎么在一个类中改变另一个类中变量的值 APPLET与网页之间的显示问题 问一个问题 工作,请兄弟们帮忙 关于Structs2 valuestack问题 多线程协作 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