java使用http发送数据请求,怎样保证数据不丢失?

跳错『 爱 』的频率 发表于: 2021-09-02   最后更新时间: 2021-09-02 19:07:00   2,196 游览

在使用httpclient发送post请求时,怎样保证数据安全可靠传输到对方服务器

springboot,数据传输到对方服务器

@Autowired
private CloseableHttpClient httpClient;

@Autowired
private RequestConfig config;
public String doPost(String url) throws Exception{
    //声明http请求
    HttpPost httpPost = new HttpPost(url);
    //装载配置信息
    httpPost.setConfig(config);
    //发起请求
    CloseableHttpResponse response = this.httpClient.execute(httpPost);
    //判断状态码是否为200
    if(response.getStatusLine().getStatusCode() == 200){
        //返回响应体内容
        return EntityUtils.toString(response.getEntity(),"UTF-8");
    }
    return null;
}
发表于 2021-09-02
添加评论

200是可以认为请求是完整的。

但是,要保证数据安全可靠传输到对方服务器,并不是一次请求决定的,必须服务端也做出相应的验证接口,来保障数据的完整性。

比如你接受到了一个列表,获取一下这个列表的总长度就可以作为验证方式。

你的答案

查看java相关的其他问题或提一个您自己的问题