作者: pingc

发起请求

jnewbie有5种请求方式:get,post,hGet,pGet,cGet

请求 配置参数 配置请求头 配置cookie 配置代理 加载动态数据 配置JS加载时间 备注
get yes yes yes yes no no 正常请求
post yes yes yes yes no no 正常请求
hGet yes yes yes yes yes yes JS兼容一般
pGet yes no no yes yes yes 需额外配置
cGet yes no no yes yes yes 需额外配置

get

  1. //创建请求客户端
  2. JHtml jHtml = new JHtml();
  3. //发起get请求
  4. JPage jPage = jHtml.get("http://localhost");
  5. //打印返回内容
  6. System.out.println(jPage);

post

  1. //创建请求客户端
  2. JHtml jHtml = new JHtml();
  3. //发起post请求
  4. JPage jPage = jHtml.post("http://localhost");
  5. //打印返回内容
  6. System.out.println(jPage);

hGet

  1. //创建请求客户端
  2. JHtml jHtml = new JHtml();
  3. //发起hGet请求
  4. JPage jPage = jHtml.hGet("http://localhost");
  5. //打印返回内容
  6. System.out.println(jPage);

pGet

phantomjs下载地址:https://phantomjs.org/download.html

  1. //配置phantomjs路径
  2. PhantomJSDriverManager.setDriverPath("C:\Users\Administrator\Desktop\phantomjs.exe");
  3. //创建请求客户端
  4. JHtml jHtml = new JHtml();
  5. //发起pGet请求
  6. JPage jPage = jHtml.pGet("http://localhost");
  7. //打印返回内容
  8. System.out.println(jPage);

cGet

chromedriver下载地址:http://npm.taobao.org/mirrors/chromedriver/
选择与Chrome浏览器对应的版本

  1. //配置chromedriver路径
  2. ChromeDriverManager.setDriverPath("C:\Users\Administrator\Desktop\chromedriver.exe");
  3. //创建请求客户端
  4. JHtml jHtml = new JHtml();
  5. //发起cGet请求
  6. JPage jPage = jHtml.cGet("http://localhost");
  7. //打印返回内容
  8. System.out.println(jPage);