常用代码块:创建httpclient

HttpGet httpGet = new HttpGet(url);
SSLContext sslcontext = SSLContexts.custom()
.loadTrustMaterial(TrustSelfSignedStrategy.INSTANCE).build();

RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(3000)
.setConnectionRequestTimeout(3000).setSocketTimeout(3000).build();

CloseableHttpClient httpclient = HttpClients.custom().setSSLContext(sslcontext)
.setSSLHostnameVerifier(new MyHostnameVerifier())
.setDefaultRequestConfig(requestConfig).build();

CloseableHttpResponse response = httpclient.execute(httpGet);

时间: 2024-08-25 04:25:08

常用代码块:创建httpclient的相关文章

常用代码块模板,get,load区别,session.get(,)参数解释,session方法总结

设置模板代码步骤:window->java->Templates->new模板代码Session session = HibernateUtils.openSession(); try { HibernateUtils.startTransaction(); /** * 具体的业务代码 */ HibernateUtils.commitTransaction(); } catch (Exception e) { HibernateUtils.rollBackTransaction(); t

Xcode 添加常用代码块

1.在Xcode 10 以后我们的代码块从右下角,跑到了右上角了(如图所示) 2.添加代码块的方式也不用像原来拖拽的方式了: 选中需要添加的代码块,右键 --> Create Code Snippet(如图所示) 自定义代码块 我们以 strong 来举例 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #ffffff; background-color: #000000 } span.s1 { color:

常用代码块:创建httpclient 2

HttpGet httpGet = new HttpGet(url);SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(new MyTrustStrategy()).build(); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(3000).setConnectionRequestTimeout(3000).setSocket

GCD的常用代码块

一.队列 1.获取全局的并发队列 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 2.创建一个串行队列 dispatch_queue_t queue = dispatch_queue_create("queueName", NULL); 3.获取主队列 dispatch_queue_t queue = dispatch_get_main_queue(); 二.

iOS 常用代码块

1.判断邮箱格式是否正确的代码: // 利用正则表达式验证 -( BOOL )isValidateEmail:( NSString  *)email { NSString  *emailRegex =  @"[A-Z0-9a-z._%+-][email protected][A-Za-z0-9.-]+\\.[A-Za-z]{2,4}" ; NSPredicate  *emailTest = [ NSPredicate   predicateWithFormat : @"SEL

iOS开发常用代码块(2)

GCD定时器 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue); dispatch_source_set_timer(timer,dispatch_walltime(NULL, 0),1.0*NS

常用代码块:java使用系统浏览器打开url

方法一:用于windows try { Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+url); } catch (IOException e1) {e1.printStackTrace(); } 方法二:通用,但会可能会抛出java.net.URISyntaxException异常. try { // 创建一个URI实例,注意不是URL url格式问题可能会有异常这里 java.net.URI ur

常用代码块:使用时间生成数据库文件名

Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss"); String fileName= "jdbc:h2:~/"+sdf.format(d); cp = JdbcConnectionPool.create(fileName, "sa", "sa");

常用代码块:java使用剪贴板复制文本

// 获得系统剪切板 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // 复制到剪切板上 StringSelection text = new StringSelection(sb.toString()); clipboard.setContents(text, null);