java HttpURLConnection 模拟 返回和预计的不一样

访问的地址是:http://aq.qq.com/cn2/login_limit/login_limit_index
public final static String CONTENT_TYPE = "Content-Type";

public static void main(String[] args) throws Exception {
    // login
    // 验证码的位置
    // Content content = getRandom("GET",
    // "http://localhost:8080/back/random.action", null, null, false,"d:/");
    Content content = getRandom(
            "GET",
            "http://captcha.qq.com/getimage?aid=2001601&0.6973676234483719",
            null, null, false, "d:/");

    // build request headers & do rate of user review
    List<String> lsit = content.getHeaders().get("Set-Cookie");
    Map<String, String> resmap = new HashMap<String, String>();
    String cookie = "";
    if (lsit != null) {
        StringBuffer sb = new StringBuffer();
        boolean isLast = false;
        int i = 0;
        for (String val : lsit) {
            i++;
            if (i == lsit.size()) {
                isLast = true;
            }
            int pos = val.indexOf("=");
            if (pos != -1) {
                String cookieName = val.substring(0, pos);
                String cookieVal = val.substring(pos + 1);
                System.out.println(cookieName + ":" + cookieVal);
                cookieVal = cookieVal.split(";")[0];
                if (isLast) {
                    sb.append(cookieName + "=" + cookieVal);
                } else {
                    sb.append(cookieName + "=" + cookieVal + ";");
                }
            }
        }
        cookie = sb.toString();
    }
    String a = "";
    System.out.print("请输入验证码:");
    BufferedReader strin = new BufferedReader(new InputStreamReader(
            System.in));
    try {
        a = strin.readLine();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("输入的数是:" + a);

    String userCode = "admin";
    String account = "1158752036";
    // String loginUrl = "http://localhost:9090/w/login.action";
    String rateReviewUrl = "http://aq.qq.com/cn2/ajax/check_verifycode?verify_code="
            + URLEncoder.encode(a, "utf-8")
            + "&account="
            + URLEncoder.encode(account, "utf-8")
            + "&session_type="
            + URLEncoder.encode("on_rand", "utf-8");
    // String rateReviewUrl =
    // "http://fdjkpoi.xicp.net/udp/baseinfo/getQQ.action";
    Map<String, String> paramMap = new HashMap<String, String>();

    // content = curl("POST", loginUrl, paramMap, resmap, false, "");
    System.out
            .println("第一次 content.getBody()= " + content == null ? "no body"
                    : content.getBody());
    // build request headers & do rate of user review
    // paramMap = new HashMap<String, String>();

    content = curl("get", rateReviewUrl, paramMap, cookie, false, "");
    // inFile(content.getBody(), "D:/sss.txt");
}

public static Content curl(String method, // 方法类型
        String sUrl,// 要解析的URL
        Map<String, String> paramMap, // 存放用户名和密码的map
        String requestHeaderMap,// 存放COOKIE的map
        boolean isOnlyReturnHeader, String path) throws Exception {// 存放文件路径
    System.out.println("-------------" + sUrl + "-------------------");
    Content content = null;
    try {

        URL getUrl = new URL(sUrl);
        // 根据拼凑的URL,打开连接,URL.openConnection函数会根据URL的类型,
        // 返回不同的URLConnection子类的对象,这里URL是一个http,因此实际返回的是HttpURLConnection

        HttpURLConnection connection = (HttpURLConnection) getUrl
                .openConnection();

        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept",
                "application/json, text/javascript, */*");
        connection.setRequestProperty("Accept-Encoding", "UTF-8");
        connection.setRequestProperty("Connection", "keep-alive");
        connection.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8");
        connection.setRequestProperty("Cookie", requestHeaderMap);

        // 进行连接,但是实际上get request要在下一句的connection.getInputStream()函数中才会真正发到
        // 服务器
        connection.connect();
        // 取得输入流,并使用Reader读取

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                connection.getInputStream(),"UTF-8"));
        String lines;
        while ((lines = reader.readLine()) != null) {

            System.out.println(lines);
        }
        reader.close();
        // 断开连接
        connection.disconnect();

    } catch (Exception e) {
        return null;
    } finally {

    }

    return content;
}

public static Content getRandom(String method, String sUrl,// 要解析的url
        Map<String, String> paramMap, // 存放用户名和密码的map
        Map<String, String> requestHeaderMap,// 存放COOKIE的map
        boolean isOnlyReturnHeader, String path) {

    Content content = null;
    HttpURLConnection httpUrlConnection = null;
    InputStream in = null;
    try {
        URL url = new URL(sUrl);
        boolean isPost = "POST".equals(method);
        if (method == null
                || (!"GET".equalsIgnoreCase(method) && !"POST"
                        .equalsIgnoreCase(method))) {
            method = "POST";
        }
        URL resolvedURL = url;
        URLConnection urlConnection = resolvedURL.openConnection();
        httpUrlConnection = (HttpURLConnection) urlConnection;
        httpUrlConnection.setRequestMethod(method);
        httpUrlConnection.setRequestProperty("Accept-Language",
                "zh-cn,zh;q=0.5");
        // Do not follow redirects, We will handle redirects ourself
        httpUrlConnection.setInstanceFollowRedirects(false);
        httpUrlConnection.setDoOutput(true);
        httpUrlConnection.setDoInput(true);
        httpUrlConnection.setConnectTimeout(5000);
        httpUrlConnection.setReadTimeout(5000);
        httpUrlConnection.setUseCaches(false);
        httpUrlConnection.setDefaultUseCaches(false);
        httpUrlConnection.connect();

        int responseCode = httpUrlConnection.getResponseCode();

        if (responseCode == HttpURLConnection.HTTP_OK
                || responseCode == HttpURLConnection.HTTP_CREATED) {
            byte[] bytes = new byte[0];
            if (!isOnlyReturnHeader) {
                DataInputStream ins = new DataInputStream(httpUrlConnection
                        .getInputStream());
                // 验证码的位置
                DataOutputStream out = new DataOutputStream(
                        new FileOutputStream(path + "/code.bmp"));
                byte[] buffer = new byte[4096];
                int count = 0;
                while ((count = ins.read(buffer)) > 0) {
                    out.write(buffer, 0, count);
                }
                out.close();
                ins.close();
            }
            String encoding = null;
            if (encoding == null) {
                encoding = getEncodingFromContentType(httpUrlConnection
                        .getHeaderField(CONTENT_TYPE));
            }
            content = new Content(sUrl, new String(bytes, encoding),
                    httpUrlConnection.getHeaderFields());
        }
    } catch (Exception e) {
        return null;
    } finally {
        if (httpUrlConnection != null) {
            httpUrlConnection.disconnect();
        }
    }
    return content;
}

public static String getEncodingFromContentType(String contentType) {
    String encoding = null;
    if (contentType == null) {
        return null;
    }
    StringTokenizer tok = new StringTokenizer(contentType, ";");
    if (tok.hasMoreTokens()) {
        tok.nextToken();
        while (tok.hasMoreTokens()) {
            String assignment = tok.nextToken().trim();
            int eqIdx = assignment.indexOf('=');
            if (eqIdx != -1) {
                String varName = assignment.substring(0, eqIdx).trim();
                if ("charset".equalsIgnoreCase(varName)) {
                    String varValue = assignment.substring(eqIdx + 1)
                            .trim();
                    if (varValue.startsWith("\"")
                            && varValue.endsWith("\"")) {
                        // substring works on indices
                        varValue = varValue.substring(1,
                                varValue.length() - 1);
                    }
                    if (Charset.isSupported(varValue)) {
                        encoding = varValue;
                    }
                }
            }
        }
    }
    if (encoding == null) {
        return "UTF-8";
    }
    return encoding;
}

// 这个是输出
public static boolean inFile(String content, String path) {
    PrintWriter out = null;
    File file = new File(path);
    try {
        if (!file.exists()) {
            file.createNewFile();
        }
        out = new PrintWriter(new FileWriter(file));

        out.write(content);
        out.flush();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        out.close();
    }
    return false;
}

public static String getHtmlReadLine(String httpurl) {
    String CurrentLine = "";
    String TotalString = "";
    InputStream urlStream;
    String content = "";

    try {
        URL url = new URL(httpurl);

        HttpURLConnection connection = (HttpURLConnection) url
                .openConnection();

        connection.connect();
        System.out.println(connection.getResponseCode());
        urlStream = connection.getInputStream();

        BufferedReader reader = new BufferedReader(

        new InputStreamReader(urlStream, "utf-8"));

        while ((CurrentLine = reader.readLine()) != null) {
            TotalString += CurrentLine + "\n";
        }

        content = TotalString;

    } catch (Exception e) {
    }

    return content;
}

}

class Content {
private String url;
private String body;
private Map> m_mHeaders = new HashMap>();

public Content(String url, String body, Map<String, List<String>> headers) {
    this.url = url;
    this.body = body;
    this.m_mHeaders = headers;
}

public String getUrl() {
    return url;
}

public String getBody() {
    return body;
}

public Map<String, List<String>> getHeaders() {
    return m_mHeaders;
}

贴上代码, 1158752036 QQ号已经被冻结,但是返回是 {"Err":"0" }
我输入没有冻结的QQ号 返回的也一样,输入错误的验证码,返回是 {"Err":"您输入的验证码有误" },证明已经通了,不知是否这个地址 还有其他的参数吗? 小白一个往大神教导

4个回答

看程序没用,自己拿fiddler调试下,看你的程序和浏览器在提交的http请求的时候有什么差异,就一目了然了。

特别是user agent, referer, post data, cookie, url这几个字段仔细看。

weixin_38735288
weixin_38735288 怎么用httpurlconnection抓取动态页面啊
一年多之前 回复
caozhy
贵阳老马马善福专门编写代码的老马就是我! 回复s345: 当然
大约 4 年之前 回复
u011576451
s345 网址输入,提交cookie有多个值,我也需要多个值吗?
大约 4 年之前 回复
caozhy
贵阳老马马善福专门编写代码的老马就是我! 回复s345: 仔细检查我说的字段
大约 4 年之前 回复
u011576451
s345 网址头部是GET方式提交的
大约 4 年之前 回复

网址访问,输入QQ:1158752036 返回的是一个页面,不知那里有问题,程序代码怎么获取到这个页面!

如楼上所说,还是少提交东西了。用抓包工具看一下,http analyzer 也是个不错的选择。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
not in运行和预计的结果不一样
我首先导入了两个表yy和表js,有相同的列bh,其中表yy的bh列有一些表js的bh列中没有的数据,现在想跳出这些yy表有但js表没有的数据,语言如下rnSELECT *rnFROM yyrnWHERE bh not in(select bh from js)rnORDER BY bh;rn但运行后一行数据也没有,为什么?表yy的bh列数据有的重复,表js的bh列的数据不重复.我觉得应该与这个没关系吧
java HttpURLConnection模拟上传图片功能
public static void Login() throws IOException{ String mimeBoundary=&quot;---------------------------7e2151351150&quot;; //String queryText=&quot;&quot;; String httpurl=&quot;http://postimages.org/json/rr&quot;; URL urlx = new ...
java用HttpURLConnection模拟post
http://www.bjjtgl.gov.cn/publish/portal0/tab72/rn[size=18px]我想用java模拟上述网站中的机动车违章情况查询系统:当用户输入车牌号和发动机号,然后返回查询数据。我该怎么做?希望懂的人帮帮我 rn最好有代码,这样好理解,我是个新手![/size]
HttpUrlConnection模拟浏览器发送请求
servlet...code package cn.itcast; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.serv...
java HttpURLConnection 模拟发送浏览器请求
使用HttpURLConnection 模拟浏览器发送(get,post)请求 上代码了: public static final String DEF_CHATSET = "UTF-8";     public static final int DEF_CONN_TIMEOUT = 30000;     public static final int DEF_READ_T
看下这个程序,结果和预计的不一样
#includernvoid interchange(int u,int v);rnint main(void)rnrnint x=5,y=10;rnprintf("originally x=%d and y=%d.\n",x,y);rninterchange(x,y);rnprintf("now x=%d and y=%d.\n",x,y);rnreturn 0;rn)rnvoid interchange(int u,int v)rnrnint temp;rntemp=u;rnu=v;rnv=temp;rnrn运行结果是rnoriginally x=5 and y=10rnnow x=5 and y=10rn为什么x和y的值没交换rn那里出了问题rn谁知道
么和预计结果不一样???foo.concat("bbbb");
public class test1 rn rn rn rn public static void main(String args[])rn rn String foo = "baseasfdvd";rn foo.concat("bbbb");rn rn System.out.println(foo);rnrnrn怎么和预计结果不一样???rn我预计是baseasfdvdbbbbrn可结果却?rnC:\testjava>java test1rnbaseasfdvd
HttpURLConnection模拟 POST 动作出错
我有下面一段代码 ,当把注释部分去掉后, 会出错,请高人帮我看一下,不胜感激rnrn不执行注释段代码,程序不会出错,URL也是可以访问的rnrn[code=Java]rnimport java.io.BufferedReader;rnimport java.io.IOException;rnimport java.io.InputStreamReader;rnimport java.net.HttpURLConnection;rnimport java.net.URL;rnimport java.net.URLConnection;rnimport java.net.URLEncoder;rnimport java.nio.charset.Charset;rnpublic class HelloWorld rn public static void main(String[] args) throws IOException rn HttpURLConnection con = null;rn rn rn String username="authenticityToken=9234f0328ba92059a816562d05988a1a8d5fc6fd";rn username=URLEncoder.encode(username, "utf-8");rn URL url = new URL("http://10.224.104.178/admin/validateT");rn con =(HttpURLConnection) url.openConnection();rn rn [color=#FF0000]/*rn con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");rn con.setRequestProperty("Content-Length", "" +Integer.toString(username.getBytes().length));rn con.setRequestProperty("Content-Language", "en-US");rn rn con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" );rn rn con.setDoInput(true);rn con.setDoOutput(true);rn con.setRequestMethod("POST");rn rn con.getOutputStream().write(username.getBytes());rn con.getOutputStream().flush();rn con.getOutputStream().close();rn */[/color] rn BufferedReader br = null;rn String charset = charset(con.getContentEncoding(), con.getContentType());rn rn try rn br = new BufferedReader(new InputStreamReader(con.getInputStream(), charset));rn for(String str = null; (str = br.readLine()) != null; ) rn System.out.println(str);rn rn finally rn if(br != null) rn br.close();rn rn rn rn private static String charset(String encoding, String contentType) rn if(encoding != null && Charset.isSupported(encoding)) rn return encoding;rn rn if(contentType == null) rn return Charset.defaultCharset().name();rn rn int index = contentType.indexOf("charset=");rn if(index < 0) rn return Charset.defaultCharset().name();rn rn String charset = contentType.substring(index + 8);rn if(!Charset.isSupported(charset)) rn return Charset.defaultCharset().name();rn rn System.out.println("charset="+charset);rn return charset;rn rnrnrn[/code]rnrn错误信息 rnrn[code=Java]rnrnException in thread "main" java.io.FileNotFoundException: http://10.224.104.178/admin/validateTrn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)rn at java.lang.reflect.Constructor.newInstance(Unknown Source)rn at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)rn at java.security.AccessController.doPrivileged(Native Method)rn at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)rn at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)rn at HelloWorld.main(HelloWorld.java:39)rnCaused by: java.io.FileNotFoundException: http://10.224.104.178/admin/validateTrn at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)rn at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown Source)rn at java.net.URLConnection.getContentEncoding(Unknown Source)rn at HelloWorld.main(HelloWorld.java:36)rnrn[/code]
HttpURLConnection模拟请求小例子
HttpURLConnection用法详解一、简介 HttpURLConnection类是另一种访问HTTP资源的方式。二、连接步骤 1、通过openConnection方法创建连接对象。 2、设置请求头和请求体 3、使用connect方法于远程对象进行连接 4、远程对象变得可用,其字段和内容变得可访问三、用法 1、创建连接 // 获取连接的URL URLurl= newURL(&quot;http:/...
Adnroid 通过HttpURLConnection模拟post表单提交
package junit; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import org.junit.Test; import com.hrtx.util.StreamTool; public class EsmTest { /** * 通过
用HttpURLConnection模拟网页登录
用HttpURLConnection模拟登录某个网站,以post的方式发送请求,然后得到response的状态码是200而不是302,页面没有重定向,返回的输入流是原来的登录页面。以下是一些关键代码,麻烦给位帮忙看看,我是新手。。。rnrnrn[code=Java]rn Map post = new HashMap();rn //post.put("__VIEWSTATE", "dDwtMTIwMTU3OTE3Nzs7Pkpv5PWSSJQutGzQO79G0NxH9kuS");//这个值从foxbug上复制下来的rn post.put("TextBox1", "20093069***");rn post.put("TextBox2", "*****");rn post.put("RadioButtonList1", "学生");rn post.put("Button","");//rn post.put("lbLanguage", "");//这两个的值在httpfox显示都是空的rn String urlStr = "http://202.116.160.170/default2.aspx";//default2.aspx是post的方法(action="default2.aspx")rnrnrn //设置请求头,建立连接rn URL url = new URL(urlStr);rn HttpURLConnection uc = (HttpURLConnection)url.openConnection();rn uc.setRequestMethod("POST");rn uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");rn uc.setRequestProperty("Host", "202.116.160.170");rn uc.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0");rn uc.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");rn uc.setRequestProperty("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");rn uc.setRequestProperty("Accept-Encoding", "gzip, deflate");rn uc.setRequestProperty("Connection", "keep-alive");rn uc.setRequestProperty("Referer", "http://202.116.160.170/");rn rn uc.setDoOutput(true);rn //uc.setFollowRedirects(true);rn uc.setDoInput(true);rnrnrn //将用户名、密码等以"username=XXX&password=***"的形式输出rn PrintWriter pw = new PrintWriter(uc.getOutputStream()); rn boolean first = true;rn for(Map.Entry pair : nameValuePairs.entrySet())rn if(first)rn first = false;rn rn elsern pw.print('&');rn rn pw.print(pair.getKey());rn pw.print('=');rn pw.print(URLEncoder.encode(pair.getValue(), "gb2312"));//content-type里的charset=gb2312,但是把得到输入流输出到控制台后,中文乱码,试过用'UTF-8"以及"GBK",结果一样。rn rn[/code]
HttpURLConnection在win7与2008 server r2下结果不一样
rnrnJSP代码:rn[code=java]rn<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>rn<%@page import="java.io.IOException"%>rn<%@page import="java.net.URL"%>rn<%@page import="java.net.HttpURLConnection"%>rn<%@page import="java.io.BufferedReader"%>rn<%@page import="java.io.InputStreamReader"%>rn<%@page import="java.net.MalformedURLException"%>rn<%@page import="java.io.OutputStream"%>rn<%rnString path = request.getContextPath();rnString basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";rn%>rnrnrnrn rn rn rn My JSP 'test.jsp' starting pagern rn rn rn rn rn rn rnrn rn rn rn <%rnrn try rn // 1. 获取访问地址URLrn URL url = new URL("https://www.fedex.com/my/");rn // 2. 创建HttpURLConnection对象rn HttpURLConnection connection = (HttpURLConnection) url.openConnection();rn /* 3. 设置请求参数等 */rn // 请求方式rn connection.setRequestMethod("GET");rn // 超时时间rn connection.setConnectTimeout(3000);rn // 设置是否输出rn connection.setDoOutput(false);rn // 设置是否读入rn connection.setDoInput(true);rn rn // 设置是否使用缓存rn connection.setUseCaches(false);rn // 设置此 HttpURLConnection 实例是否应该自动执行 HTTP 重定向rn connection.setInstanceFollowRedirects(true);rn // 设置使用标准编码格式编码参数的名-值对rn connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");rn connection.setRequestProperty("Accept-Encoding", "gzip, deflate, br");rn connection.setRequestProperty("Referer", "https://www.fedex.com/my/");rn connection.setRequestProperty("Host", "www.fedex.com");rn connection.setRequestProperty("Connection", "keep-alive");rn connection.setRequestProperty("Upgrade-Insecure-Requests", "1");rn connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0"); rn rn // 连接rn rn connection.connect();rn /* 4. 处理输入输出 */rn // 写入参数到请求中rn // 从连接中读取响应信息rn String msg = "";rn int code = connection.getResponseCode();rn if (code == 200) rn String sessionId = ""; rn String cookieVal = ""; rn String key = null; rn for(int i = 1; (key = connection.getHeaderFieldKey(i)) != null; i++) rn if(key.equalsIgnoreCase("set-cookie")) rn cookieVal = connection.getHeaderField(i); rn cookieVal = cookieVal.substring(0, cookieVal.indexOf(";"));rn sessionId = sessionId + cookieVal + ";"; rn out.println(cookieVal+" ");rn rn rn rn BufferedReader reader = new BufferedReader(rn new InputStreamReader(connection.getInputStream()));rn String line;rnrn while ((line = reader.readLine()) != null) rn msg += line + "\n";rn rn reader.close();rn rn // 5. 断开连接rn connection.disconnect();rnrn // 处理结果rn //out.println(msg);rn catch (MalformedURLException e) rn e.printStackTrace();rn catch (IOException e) rn e.printStackTrace();rn rn %>rn rnrnrnrn[/code]rnrnrn以上JSP代码放在2003 Server 64位,Tomcat6,JDK6下获取的结果:rnrnsiteDC=edcrn fdx_cbid=31214489081519780287031840257131 rnak_bmsc=55EE64131225D40487CD1B061FC4D9116B0E2CC1D3280000BF01965AD51B2372~pluwIHQvxHq+mog9P18xmSe+PJs0gv/8KkIg9fkObdJEgL+/pOF/t+c3s5kFSgd1SceOPzhbDHEuZoKcm6wQtKnO4FFfWMIM+jdkIAHtfXNISkSxGwgOMrar3hKyjkTzPq/aFrOsGGrGBdIW0VYbkjAARJvKBItjd+jM3ugxdMU7nwQod3/PDaFLO9sAZivBSjikwl7gS7v6D8Dj7xoIcmsH6zE4P+hoR3qh36r+G/MLo= rnbm_mi=DF0B7D3B47EF16D48131FE8A2FA5F3D1~LEYRDXYiG/BFmIpYVH9K51V731DW2D+ukQEXXwtFA5/GUfHR2b9mYPdhSn8ZtmzEmD2A4lonV2fmXSwgx8ddqSaaPaNmargsZvGISabuNCMQ8BDS4FZH7hsQ8sMdcimiAdrQCQjEgHzoA+KVn+IaA5saTYnrXrKZFMxlXfta0cX/0E5xIxNgAgVXE5V1h75xgfRC7BnT/hxU1Pq7Eo8/rbzoZwn/Pv1clCK8jgM+Axw= rnrn获取到了:ak_bmsc与bm_mi两个cookie值,将代码放在2008 server 64 r2+Tomcat6+JDK6下就获取不到这两个cookie值,各位大神有没有遇到过相关的情况?是否JDK在不同的平台下使用的连接认证不一样的原因.先谢谢大家
不一样的模拟unix软件
模拟unix软件,如果您不想要装实用软件的话,装它就ok了,一样的功能,一样的使用方法
java HttpURLConnection 使用示例
本例子是 java 的 HttpURLConnection 使用方法,比较简单,但是涵盖了post和get两种方法,而且处理了乱码。
java怎么预计压缩文件的时间
java程序,一个方法用来压缩文件,由于文件可能会比较大,我希望能先预计到需要压缩多久,将信息反馈到页面。我使用的是第一个是:org.apache.tools.ant.taskdefs.Zip的ZIP压缩方法,又找了个调用winrar的压缩 都不能在压缩之前预计到时间, 请问有没有什么好的方法能先预计到压缩时间的?
java HttpURLConnection工具
java HttpURLConnection示例 HttpURLConnection工具
Java的HttpURLConnection的封装类 v3.0
用于对基于HTTP的服务进行抓取 HttpClient 现在是HttpComponents 把问题搞复杂了 其实Java内置的HttpURLConnection很好的 内含文档 使用方法见http://blog.csdn.net/jdgdf566/article/details/17039693
Java的HttpURLConnection的封装类
用于对基于HTTP的服务进行抓取 HttpClient 现在是HttpComponents 把问题搞复杂了 其实Java内置的HttpURLConnection很好的 内含文档 使用方法见http: blog csdn net jdgdf566 article details 16357677
java android httpURLConnection的封装
针对httpURLConnection 的简单封装,简单易用,支持上传下载 用法自已研究吧、
Java Web基础入门第四十讲 使用HttpUrlConnection模拟浏览器
在手机开发中,要想向服务器发送请求和读取服务器回送回来的响应,我们就需要使用到HttpUrlConnection这个类。关于这个类的详解,可以查看Java API帮助文档。 现在我们使用HttpUrlConnection这个类来模似IE,向服务器发送请求和读取服务器回送回来的响应。 处理服务器回送的http响应 在服务器端新建一个servlet——ServletDemo1.java,代码如下所示
HttpurlConnection
在正在对HttpurlConnection进行了解,一直在使用公司的一个框架。一天到晚也就这么用,还真没想过它到底是怎么搞的。网上找了写说法,感觉都不怎么好,请各位给指点一下?
Httpurlconnection
代码包含了httpurlconnection基本操作,一些正常的操作。
Java Web 学习笔记之三: HttpURLConnection 模拟表单上传文件
利用HttpURLConnection发送post请求上传文件
Java 利用 HttpURLConnection 读取页面 返回字节流(生成静态页面)
Java 利用 HttpURLConnection 读取页面 返回字节流(生成静态页面)
HttpURLConnection
利用HttpURLConnection通过用户传入的参数来链接到在用户所需的网址,如果是多个不同的用户同时访问该方法时,会不会有个别用户的信息会被其他的用户传入信息所替代了?
返回datatable和返回实体有什么不一样?
最近在做机房收费系统,在三层架构中,我们返回实体和datatable有什么不一样捏?或者说性能方面有什么不一样?在B/S中都是泛型,在C/S中有时泛型不太灵活(这里我讲的是报表),请高手指点rn
HttpURLConnection文件下载\httpURLConnection文件下载
HttpURLConnection文件下载\httpURLConnection文件下载
HttpURLconnection
httpurlconnection网络请求,get请求, post请求,封装
HttpUrlConnection
蓝鸥Android开发之初窥门径的学习主要针对一下几点,大家好好学习n1.Android四大组件的基本使用n2.常用的基本控件和布局的使用n3.Android的网络编程n4.Android中的多线程开发
java httpURL连接远程服务器并返回数据(httpurlconnection)
package com.jiucool.www.struts.action;   import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.Inpu
android 使用Java自带的HttpURLConnection 连接网络 读取返回数据
        @Override     protected void onCreate(Bundle savedInstanceState) {         // TODO Auto-generated method stub         super.onCreate(savedInstanceState);         setContentView(R.layout....
HttpURLConnection模拟浏览器http请求【转】
本文是参考网络文章测试整理,报歉忘记参考地址了,要是作者有意见就请联系我.文中只是对程序的运行做了测试,但理论没有去考证正确性,等后面研究下再完善.这只是做参考 1 import java.io.BufferedReader; 2 import java.io.DataOutputStream; 3 import java.io.InputStreamReader; ...
HttpURLConnection模拟POST上传文件,乱码问题请指教
[code=Java]rn...rnconn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------7d92ce11d0204");rn...rn[/code]rn用的是正常的拼接字符串的方法,出现乱码问题.rn比如我想传一个字符型中文参数和一个中文文件名的文件,在拼接字符串时应该怎么写?rn我试过new String("内容".getBytes(项目通用的charset,我这里是UTF-8)),但是有些字符会有问题,比如"什么"到后台用apache-fileupload解析new String(变量.getBytes("iso-8859-1"), "UTF-8"),结果就是乱码,而有些字符是正常的.rnrn如果用URLEncoder.encode("内容",charset),再在后台解码固然可以解决这个问题,但在jsp中普通上传的真正过程是什么样的呢?为什么不会出现乱码现象?rnrn请教高人!
预计今年发布的Vue3.0到底有什么不一样的地方?
还有几个月距离vue2的首次发布就满3年了,而vue的作者尤雨溪也在去年年末发布了关于vue3.0的计划,如果不出意外,我们将在今年的某个时间点见证Vue3.0的发布,虽然前几天在《StateOfJS: 2018年JavaScript生态圈趋势报告》一文中我们看到目前Vue的使用者比React还少了不少,但在Github上Vue的sta...
Android模拟表单提交文字和图片(HttpClient AND HttpURLConnection)
在HttpClient还没有被废弃之前了,感觉模拟表单提交还是比较简单的,因为有MultipartEntityBuilder的支持。看下面代码:private String uploadFile(String url, HttpEntity entity) { HttpClient httpClient=new DefaultHttpClient();// 客户端 HTTP 请求
std::regex库执行情况怎么和预计的不一样?求正则帝
用std::regex分析网页数据,正则我先用工具测试了运行正常,但到了std::regex下死活匹配不到,我用了简单的数据进行测试,还是不行,大家帮忙看看是我写错了么?rnrn源文本:rn[code=html][/code]rnrn正则:rn[quote]"./n(.*)">[/quote]rnrn我是想抓取到源文件里的n0866_mitsuka_koizumi_tg_j.html这个网址。这里的正则用工具测试能正常匹配到rnrn下面用std::regex库rn[code=c]rnstd::smatch m;rnstd::regex re("\"./n(.*)\">");rnstrBuffer = "";rnwhile (std::regex_match(strBuffer, m, re, std::regex_constants::match_default))rnrn cout << "================" << endl;rn cout << m[0] << endl << m[1] << endl;rnrn[/code]rnstd::regex_match函数一直返回0,改为用 std::regex_search函数,能匹配到,但结果变成0866_mitsuka_koizumi_tg_j.html">rnrn我凌乱了。。[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/19.gif][/img]rn自己摸索了很长时间,百思不得骑姐啊。。。
使用HttpURLConnection链接服务返回数据
            URL url = new URL(urlStr); //url地址            HttpURLConnection con = (HttpURLConnection) url.openConnection();            con.setDoOutput(true);            con.setRequestProperty(&quot;Pragma:...
HttpURLConnection请求返回数据部分乱码问题
问题:返回数据部分中文乱码,当中文字数为偶数时,不出现乱码;中文字数为奇数时,最后一位中文是以“??结尾。解决方案:发送post请求的接口已设置filer:encoding=UTF-8,且工作空间字符集设置为UTF-8。服务接口返回内容是以UTF-8格式发送的,接收时怎么会出现GBK格式?继续深究,发现HttpURLConnection 接收返回内容时没有设置字符集,此时使用默认字符集GBK,即B...
HttpURLConnection运行后为什么没返回代码?
[img=https://img-bbs.csdn.net/upload/201703/24/1490332018_46174.jpg][/img]rn[img=https://img-bbs.csdn.net/upload/201703/24/1490332317_672293.jpg][/img]rn[img=https://img-bbs.csdn.net/upload/201703/24/1490332046_163142.jpg][/img]rn权限申请了,请问运行后点击按钮为什么没有返回HTML代码??
新手求助!HttpURLConnection有时返回乱码的问题!
新手刚开始学习Java,弄个Get方式获取网页源码的代码,尝试获取Baidu首页的源码rn但是这里问题就来了,不停地多次运行(期间什么都不改变),有时候返回的数据就是好的,有时候返回的就是乱码,这是为啥????rn求大神解释!!!!!rn代码很简单:rn[code=java]tryrn rn url = new URL("http://www.baidu.com");rn HttpURLConnection httpURLConnection = (HttpURLConnection) urlrn .openConnection();rn httpURLConnection.setRequestMethod("GET");rn httpURLConnection.setReadTimeout(5000);rn InputStream inputStream = httpURLConnection.getInputStream();rn InputStreamReader inputStreamReader = new InputStreamReader(rn inputStream, "utf-8");rn BufferedReader bufferedReader = new BufferedReader(rn inputStreamReader);rn StringBuffer strBuffer = new StringBuffer();rn String line=null;rn while((line=bufferedReader.readLine())!=null)rn strBuffer.append("\n" + line);rn rn System.out.println(strBuffer);rn bufferedReader.close();rn catch (MalformedURLException e)rn rn e.printStackTrace();rn catch (IOException e)rn rn e.printStackTrace();rn [/code]rnrn在网上搜索的很多,可是都是编码问题,改了编码就好了,但是我这个重点是:rn有时候正常,有时候就乱码。。。rn乱码还复制不出来,真是醉了rn还是用过百度到的类似代码,也是有时好有时坏。。。rn
相关热词 c# login 居中 c# 考试软件 c# 自然语言分析 c# 分段读取文件 c# 泛型反射 c#打断点 c# 时间转多少秒 c# 线程函数加参数 c# modbus 读取 c#查询集合表