本帖最后由 xyz 于 2013-06-30 22:08:12 编辑

解决方案 »

  1.   

    应该是不能用get的,开源项目httpclient比较好用post地址:http://5pi.cn/member/checklogin.php
    参数:
    username:mememomo
    password:******
    chkcode:5354
    login:1
      

  2.   

    给你一个模拟登录qq空间的例子:登录方法:        public static String login(final String qq,final String password){
                    HashMap<String, String> params=new HashMap<String, String>();
                    params.put("login_url", "http://pt.3g.qq.com/s?aid=nLogin");
                    params.put("sidtype", "1");
                    params.put("loginTitle", "手机腾讯网");
                    params.put("bid", "0");
                    params.put("qq", qq);
                    params.put("pwd", password);
                    params.put("loginType", "1");
                    try {
                            String response=WebUtils.doPost(QQ_LOGIN_URL, params, 0, 0);
                            int sidIndex=response.indexOf("sid");
                            SID=response.substring(sidIndex+4, sidIndex+28);
                    } catch (IOException e) {
                            e.printStackTrace();
                    }
                    return SID;
            }WebUtils类的doPost方法:
            
    public static String doPost(String url, Map<String, String> params,int connectTimeout,int readTimeout) throws IOException {
                    String query=buildQuery(params, DEFAULT_CHARSET);
                    byte[] content=null;
                    if(query!=null){
                            content=query.getBytes(DEFAULT_CHARSET);
                    }
                    return doPost(url, CTYPE, content, connectTimeout, readTimeout);
            }        public static String doPost(String url, String ctype, byte[] content,int connectTimeout,int readTimeout) throws IOException {
                    HttpURLConnection conn = null;
                    OutputStream out = null;
                    String rsp = null;
                    try {
                            try{
                                    conn = getConnection(new URL(url), METHOD_POST, ctype); 
                                    conn.setConnectTimeout(connectTimeout);
                                    conn.setReadTimeout(readTimeout);
                                    out = conn.getOutputStream();
                                    out.write(content);
                                    rsp = getResponseAsString(conn);
                            }catch(IOException e){
                                    throw e;
                            }
                    }finally {
                            if (out != null) {
                                    out.close();
                            }
                            if (conn != null) {
                                    conn.disconnect();
                            }
                    }
                    return rsp;
            }        private static HttpURLConnection getConnection(URL url, String action, String ctype)
                            throws IOException {
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    conn.setRequestMethod(action);
                    conn.setDoInput(true);
                    conn.setDoOutput(true);
                    conn.setRequestProperty("Accept", "text/xml,text/javascript,text/html");
                    conn.setRequestProperty("User-Agent", USER_AGENT);
                    conn.setRequestProperty("Content-Type", ctype);
                    return conn;
            }        private static String getStreamAsString(InputStream stream, String charset) throws IOException {
                    try {
                            BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset));
                            StringWriter writer = new StringWriter();
                            char[] chars = new char[256];
                            int count = 0;
                            while ((count = reader.read(chars)) > 0) {
                                    writer.write(chars, 0, count);
                            }
                            return writer.toString();
                    } finally {
                            if (stream != null) {
                                    stream.close();
                            }
                    }
            }
      

  3.   

    返回信息是验证码出错,说明楼主get方式提交时成功的,只是验证码输入错了
    看了下paramStr的拼凑
     String paramStr = "?"+ "&userName=" + userName + "&password=" + password + "&chkcode=" + chkcode+"&login=1"; //验证码和login参数直接少了个&导致你验证码变成了你输入的1386login=1了所以返回了验证码出错。楼主把这个&符号加上再试试吧
      

  4.   

    补充下
    String paramStr = "?"+ "&userName=" + userName + "&password=" + password + "&chkcode=" + chkcode+"&login=1"; 
    第一个参数后面不用跟&正确的格式应该是
    String paramStr = "?"+ "userName=" + userName + "&password=" + password + "&chkcode=" + chkcode+"&login=1"; //参数名userName前面的&去掉
      

  5.   

    应该不是post 的问题,数据没有获取到应该是参数问题。