zoukankan      html  css  js  c++  java
  • 1-描述和简单示例

    可使用的验证码

    a). 知乎的登录界面--验证码 https://www.zhihu.com/captcha.gif?r=1509626035515&type=login
    
    b). 微博注册验证码
    http://diablo.alibaba.com/captcha/click/get.jsonp?sessionid=0152JIZgtMjy7iQLwB8JakWfF-ia0wQJ0XVIoC9KSI9E0tK5acyPEvg7y1foJaZY8nxt3RZ0fXiPaTW4hx2ZxcMW1LHCkTKrSsMSx-K5SQWQIzmgekUSpnBorkOPHqpxetmk0vqI3y4YWx_TGy45OfWg&identity=FFFF00000000016C467E&style=ncc&lang=cn&v=845&callback=jsonp_05557453445615215
    
    c). 博客园登录有图形验证码
    
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>4.5.3</version>
            </dependency>
    

    1.0 fluent简化代码

    但是目前不知如何设置代码
    

    1.1 普通post请求

    	public static void main(String[] args) throws IOException {
    
    		// 创建httpclient
    		CloseableHttpClient httpclient = HttpClients.custom().build();
    		// 请求地址和参数
    		HttpPost httpPost = new HttpPost("http://10.253.181.3:32300/syncDataNotify");
    
    		// 设置请求域
    		httpPost.setEntity(new StringEntity(requestContent, Charset.forName("UTF-8")));
    
    		// 打印requestdata
    		System.out.println(requestContent);
    
    		// 设置header信息
    		httpPost.setHeader("Content-Type", "application/soap+xml;
    
    
    		HttpResponse response = httpclient.execute(httpPost);
    
    		// 获取响应实体
    		HttpEntity entity = response.getEntity();
    
    		// 打印响应内容
    				System.out.println("Response content: " + EntityUtils.toString(entity));
    
    		// 关闭连接,释放资源
    		httpclient.close();
        }
    

    1.2 最普通的http请求-代理

    //创建
    CloseableHttpClient httpclient = HttpClients.createDefault();
    //请求地址
    HttpGet httpget = new HttpGet("http://xinsheng.huawei.com/cn/index");
    System.out.println("executing request " + httpget.getURI());
    //执行请求
    HttpResponse response = httpclient.execute(httpget);
    
    //获取响应实体
    HttpEntity entity = response.getEntity();
    

    1.2 设置请求代理(Post请求)-http

    //代理等同在header中设置Proxy-Authorization属性,其中描述用户名和密码(base64编码)
    Proxy-Authorization: Basic ejAwMzU4Nzg0NTQ6MXFheXVpdXo=
    (等同信息z0035878454:1qayuiuz)
    
    	public static void main(String[] args) throws IOException {
    
    		// 证书信息,可添加多个
    		CredentialsProvider credsProvider = new BasicCredentialsProvider();
    		credsProvider.setCredentials(new AuthScope("proxyhk.huawei.com", 8080),
    				new UsernamePasswordCredentials("sdfsdfsd", "sdfsdfsdf"));
    
    		// 创建httpclient
    		CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
    
    		// 请求地址和参数
    		HttpPost httpPost = new HttpPost("http://www.webservicex.net/geoipservice.asmx");
    
    		// 请求信息中设置使用的代理
    		HttpHost proxy = new HttpHost("proxyhk.huawei.com", 8080);
    		RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
    		httpPost.setConfig(config);
    
    		// 请求域信息
    		Document document = DocumentHelper.createDocument();
    
    		// 增加命名空间
    		Namespace sopa12 = Namespace.get("soap12", "http://www.w3.org/2003/05/soap-envelope");
    
    		// 添加带命名空间的节点
    		Element eleSoap12 = document.addElement(new QName("Envelope", sopa12))
    				.addAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema")
    				.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    
    		// dom转xml
    		String requestContent = document.asXML();
    
    		//设置请求域
    		httpPost.setEntity(new StringEntity(requestContent, Charset.forName("UTF-8")));
    
    		// 打印requestdata
    		System.out.println(requestContent);
    
    		// 设置header信息
    		httpPost.setHeader("Content-Type", "application/soap+xml; charset=utf-8");
    
    		try {
    			// 请求地址
    			System.out.println("executing request " + httpPost.getURI());
    			// 执行请求
    			HttpResponse response = httpclient.execute(httpPost);
    
    			// 获取响应实体
    			HttpEntity entity = response.getEntity();
    
    			// 打印响应内容长度
    			System.out.println("Response content length: " + entity.getContentLength());
    
    			// 打印响应内容
    			System.out.println("Response content: " + EntityUtils.toString(entity));
    
    		} finally {
    			// 关闭连接,释放资源
    			httpclient.close();
    
    		}
    	}
    

    1.3 发起https请求

    
    
  • 相关阅读:
    JavaScript实现类的private、protected、public、static以及继承
    OSS网页上传和断点续传(STSToken篇)
    OSS网页上传和断点续传(OSS配置篇)
    Linq sum()时遇到NULL
    SQLSERVER事务日志已满 the transaction log for database 'xx' is full
    笔记本高分辨软件兼容问题,字体太小或模糊
    H5上传图片之canvas
    An error occurred while updating the entries. See the inner exception for details.
    无限级结构SQL查询所有的下级和所有的上级
    SQLserver 进程被死锁问题解决
  • 原文地址:https://www.cnblogs.com/Desneo/p/7347096.html
Copyright © 2011-2022 走看看