HttpClient POST/SET方法
2021-05-14 10:29
标签:判断 处理 exce methods vat array 十年 create 的区别 前言: 网络API接口:https://api.apiopen.top/searchMusic 此API接口返回类型为JSON格式类型 GET:从指定资源请求数据 POST:向指定资源提交要被处理的数据 GET与POST的区别: ①GET在浏览器回退时是无害的,而POST会再次提交请求。 ②GET只支持URL编码。 ③GET参数通过URL传递,参数直接暴露在URL中会泄露信息,POST通过Request body传递不会有这样的问题。 ④GET请求在URL中传递参数有长度限制,POST没有长度限制。 ⑤对POST请求会险发送Header,服务器相应成功,在发送Date,服务器再次响应,需响应两次。GET会把Header与Date一起发送到服务端,服务器只响应一次。 一、POST方法 创建POST方法类 调用POST方法类 二、SET方法 创建SET方法类 调用SET方法类 HttpClient POST/SET方法 标签:判断 处理 exce methods vat array 十年 create 的区别 原文地址:https://www.cnblogs.com/yogouo/p/11949355.html 1 package com.HttpClient.Test;
2
3 import java.io.IOException;
4 import java.util.ArrayList;
5
6 import org.apache.http.HttpEntity;
7 import org.apache.http.HttpHost;
8 import org.apache.http.NameValuePair;
9 import org.apache.http.client.ClientProtocolException;
10 import org.apache.http.client.config.RequestConfig;
11 import org.apache.http.client.entity.UrlEncodedFormEntity;
12 import org.apache.http.client.methods.CloseableHttpResponse;
13 import org.apache.http.client.methods.HttpPost;
14 import org.apache.http.impl.client.CloseableHttpClient;
15 import org.apache.http.impl.client.HttpClientBuilder;
16 import org.apache.http.util.EntityUtils;
17
18 import com.HttpClient.jiexi.HttpClient_jiexi;
19
20 public class HttpClient_post {
21
22 private String entityStr;
23 HttpClient_jiexi JSONTOOL = new HttpClient_jiexi();
24
25 //封装POST方法
26 public String post(String POST_URL,ArrayList
1 package com.HttpClient.Test;
2
3 import java.util.ArrayList;
4 import org.apache.http.NameValuePair;
5 import org.apache.http.message.BasicNameValuePair;
6 import org.json.JSONException;
7 import org.testng.annotations.Test;
8
9 public class HttpClient_case1 {
10
11 HttpClient_post post = new HttpClient_post();
12 private String POST_URL = "https://api.apiopen.top/searchMusic";
13 private String entity;
14 private ArrayList
package com.HttpClient.Test;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
public class HttpClient_set {
public String entityStr ;
public CloseableHttpResponse response ;
public String set(String GET_URL,ArrayList
package com.HttpClient.Test;
import java.net.URISyntaxException;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.testng.annotations.Test;
public class HttpClient_case1 {
HttpClient_set set = new HttpClient_set();
private String SET_URL = "https://api.apiopen.top/searchMusic";
private String entity;
private ArrayList
下一篇:简单地认识一下 HTML
文章标题:HttpClient POST/SET方法
文章链接:http://soscw.com/index.php/essay/85570.html