怎么判断旺旺是否在线   不要那个返回图片的代码,要其他的.
求高手指教。感激不尽、、、、

解决方案 »

  1.   

    就是怎么判断旺旺是否在线,有这样一个链接 http://scs1.sh1.china.alibaba.com/online.atc?v=1&uid=wangbinbinda&s=2可以转向在线和不在线的图片地址。如果是获得在线和不在线的图片怎么解析··我用 HttpURLConnection读取到的输入流是一个图片的但全是乱码应该怎么解析。还有一个方法是得到他这个地址转向的地址可以判断是转向在线图片或不在线图片地址,问题是不知道怎么获得转向后的地址
      

  2.   


    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();
        } 
    }}
      

  3.   

    这是第一次请求:Request URL:http://scs1.sh1.china.alibaba.com/online.atc?v=1&uid=wangbinbinda&s=2
    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)
      

  4.   

    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