public class VoteHandler implements IVoteHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(RecorduvpvHandler.class);

    @Override
public void invoke() {
final String postUrl = "http://localhost:8080/v1/vote/taskEnableControlVote";
BufferedReader bufferedReader = null;
try {
URL url = new URL(postUrl);
// 打开和url之间的链接
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
// 设置请求属性
conn.setRequestProperty("connection", "Keep-Alive"); conn.setDoOutput(true);
conn.setDoInput(true); // Set the post method. Default is GET
conn.setRequestMethod("POST");
// Post cannot use caches
// Post 请求不能使用缓存
conn.setUseCaches(false); // 定义BufferedReader输入流来读取url相应 bufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line;
String result = "";
while ((line = bufferedReader.readLine()) != null) {
result += line;
}
LOGGER.info("请求响应结果:"+ JSON.toJSONString(result));
}catch (Exception e){
LOGGER.info("请求异常:"+e.getMessage());
} finally {
try {
if (bufferedReader != null) {
bufferedReader.close();
}
}catch (Exception e){
LOGGER.info("流关闭异常:"+e.getMessage());
}
}
}
}

  

java 发送 http 请求的更多相关文章

  1. Java发送Http请求并获取状态码

    通过Java发送url请求,查看该url是否有效,这时我们可以通过获取状态码来判断. try { URL u = new URL("http://10.1.2.8:8080/fqz/page ...

  2. 通过java发送http请求

    通常的http请求都是由用户点击某个连接或者按钮来发起的,但是在一些后台的Java程序中需要发送一些get或这post请求,因为不涉及前台页面,该怎么办呢? 下面为大家提供一个Java发送http请求 ...

  3. Java发送HTTPS请求

    前言 上篇文章介绍了 java 发送 http 请求,大家都知道发送http是不安全的 .我也是由于对接了其他企业后总结了一套发送 https的工具.大家网上找方法很多的,但是可不是你粘过来就能用啊, ...

  4. 使用Java发送Http请求的内容

    公司要将自己的产品封装一个WebService平台,所以最近开始学习使用Java发送Http请求的内容.这一块之前用PHP的时候写的也比较多,从用最基本的Socket和使用第三方插件都用过. 学习了J ...

  5. Java发送socket请求的工具

    package com.tech.jin.util; import java.io.ByteArrayOutputStream; import java.io.IOException; import ...

  6. Java发送Http请求

    package com.liuyu.test; import java.io.BufferedReader; import java.io.IOException; import java.io.In ...

  7. 编写爬虫(spider)的预备知识:用java发送HTTP请求

    使用原生API来发送http请求,而不是使用apache的库,原因在于这个第三方库变化实在太快了,每个版本都有不小的变化.对于程序员来说,使用它反而会有很多麻烦,比如自己曾经写过的代码将无法复用. 原 ...

  8. Java发送post请求

    package com.baoxiu.test; import java.io.BufferedReader;import java.io.InputStreamReader;import java. ...

  9. java发送post请求 ,请求数据放到body里

    java利用httpclient发送post请求 ,请求数据放到body里. /** * post请求 ,请求数据放到body里 * * @author lifq * * 2017年3月15日 下午3 ...

  10. JAVA发送HttpClient请求及接收请求结果

    1.写一个HttpRequestUtils工具类,包括post请求和get请求 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2 ...

随机推荐

  1. Building Web Apps with SignalR, Part 1

    Building Web Apps with SignalR, Part 1 In the first installment of app-building with SignalR, learn ...

  2. .sdp文件格式介绍

    最近做RTSP流播放,需要了解.sdp这种会话描述的文件格式,当然,里面的具体语法有SDP解析器来分析.但是我需要大概了解一些字段的意思,它是文本描述的,采用key value的形式描述. https ...

  3. alias, bg, bind, break, builtin, caller, cd, command,

    bash,  :,  .,  [, alias, bg, bind, break, builtin, caller, cd, command,       compgen, complete, com ...

  4. 如何消除word中的回车符号

    打开文字编辑页面,在菜单栏上选择工具-选项-视图-格式标志中的“段落标志”复选框前面的“√”去掉即可.  附件:

  5. 通过JS触发TextBox的ontextchanged事件,并获取TextBox所在GridView的那一行

    protected void txtInsNum_TextChanged(object sender, EventArgs e) { TextBox t = (TextBox)sender; Grid ...

  6. android设置组件所占的比例

    当我们使用linearlayout线性布局,放置三个textview空间,设置android:layout_width属性为wrap_content,并分别设置android:layout_weigh ...

  7. [LeetCode] 237. Delete Node in a Linked List 解题思路

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  8. Contest - 第10届“新秀杯”ACM程序设计大赛网络资格赛 赛后信息(晋级名单·正式版)

    2014_acm_fresh_0057 刘畅 20131620 2014_acm_fresh_0099 汪哲 20132185 2014_acm_fresh_0086 陈顺 2014111776 20 ...

  9. solr索引

    solr索引 当我们真正进入到Lucene源代码之中的时候,我们会发现: • Lucene的索引过程,就是按照全文检索的基本过程,将倒排表写成此文件格式的过程. • Lucene的搜索过程,就是按照此 ...

  10. mongodb授权登录

    mongodb版本为3.2(目前最新),演示的是linux下的mongodb授权认证 第一次登录不启动授权(mongo默认不启动) ./mongod --dbpath=/home/db/data -- ...