记录一次URL中有特殊字符怎么处理?
你out了,赶紧换
RestTemplate 吧!
进入正题,直接实战!!!
import java.util.HashMap;
import java.util.Map; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate; @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TestUrl { @Autowired
private RestTemplate restTemplate; /*
* get无参
*/
@Test
public void testNoParameter() {
String object = restTemplate.getForObject(
"http://127.0.0.1/findAllStorageDevice", String.class);
System.out.println("11111111111" + object);
} /*
* get有参
*/
@Test
public void testYesParameter() {
Map<String, String> map = new HashMap();
map.put("sdId", "res$cc$20180524113123$962c4ded-d1df-49ca-92d3-cfbca5eb28ea");
String object = restTemplate.getForObject(
"http://127.0.0.1/findStorageDeviceById?sdId={sdId}",
String.class, map);
System.out.println("11111111111" + object);
} /*
* post
*/ @Test
public void testPost() {
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("username", "11");
map.add("password", "22");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
ResponseEntity<String> postForEntity = restTemplate.postForEntity("http://127.0.0.1/login", map,
String.class);
System.out.println("11111111111" + postForEntity); }
}
package app.util; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
public class urlTest { public static void main(String[] args) throws InterruptedException { RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
//map.add("opUsername", "32322");
HttpHeaders headers = new HttpHeaders();
restTemplate.setErrorHandler(new CustomErrorHandler()); headers.add("token", "5a140050-ef25-4fe2-ada7-7ae98d6d2246"); HttpEntity<MultiValueMap<String, Object>> httpEntity1 = new HttpEntity<MultiValueMap<String, Object>>(map,headers);
String url1="http://127.0.0.1/find";
ResponseEntity<String> entity1 = restTemplate.exchange(url1, HttpMethod.GET, httpEntity1, String.class);
System.out.println("2"+entity1.getStatusCode());
System.out.println("2"+entity1.getBody()); } }
记录一次URL中有特殊字符怎么处理?的更多相关文章
- URLEncode解决url中有特殊字符的问题
问题:图片上传后的url地址中有&等特殊字符,页面传到后端时被自动处理成了& 解决:前端对url进行URLEncode,后端收到后进行URLDecode 总结:需要在请求u ...
- MVC 记录操作日志与过滤特殊字符
最近进行的MVC系统需要用到记录操作日志和过滤特殊字符的功能,如果每个action中都调用记录日志的方法就太麻烦了,所以根据需要结合mvc的过滤机制 写了个特殊字符验证与记录操作日志的公用类: pub ...
- curl 下载地址中有特殊字符解决方案
curl 下载地址中有特殊字符解决方案 情况 使用 curl 下载 地址中带有 特殊字符的时候 比如下面这个地址.实际访问地址不正确,参数丢失问题 curl -o kspf.jpeg https:// ...
- 网址URL中特殊字符转义编码
网址URL中特殊字符转义编码字符 - URL编码值空格 - %20" - %22# - %23% - %25& - %26( - %28) - %29+ - %2B, - %2C/ ...
- Tomcat8升级后URL中特殊字符报错出现原因
请求带上花括号等字符,请求无法送达服务端,报错: Failed to load resource: the server responded with a status of 400 () https ...
- URL传值特殊字符处理
问题:url传递的值中有特特殊字符,比如"<"或者">"会导致传递的参数被截短,也就是特殊字符之后的值传递不过去(例如:var list=" ...
- Mysql删除表名中有特殊字符的表
由于公司业务和应用的调整,之前在Mysql中的很多表都不需要了,故需要对数据库进行整理. 刚开始,我在想:不就删除一些表吗?很好解决,写个简单的脚本就可以了.我先看了数据库中有80000多个表,很 ...
- 033 Url中特殊字符的处理
在url跳转页面的时候,参数值中的#不见了,一直没有处理,今天有空看了一下,后来发现后台的过滤器之类的都没有处理,就比较奇怪了,原来是特殊字符的问题. 一:Url中的特殊字符 1.说明 这里还是需要做 ...
- js中有特殊字符的编码格式
在get和post方法中,如果传入的参数值有特殊字符,如:“&”,在get中的url需要拼接,可以使用encodeURICompontent来编码来转化 回调就是在上面传递实际参数,传递给aj ...
随机推荐
- 计算方法执行完的耗时 c#
Stopwatch watch = Stopwatch.StartNew(); //要执行的方法 test(); watch.Stop(); Console.WriteLine(string.Form ...
- 如何有效避免Essay写作抄袭
每到学期末的时候,各种考试,论文以及作业数不胜数,压得留学党们快要喘不过气了.我想比起写论文,同学们更操心的问题应该是:Plagiarism.要知道在国外Plagiarism的这种行为在学术中是零容忍 ...
- GDI+3
关于这个的例子其实网上已经有这方面的资料了,但是为了文章的完整性,还是觉得有必要讲解.我们先来看一下效果: ( 图2 )接下来看看这是如何做到的. 思路:聊天窗体上有一个截图按钮,点击按钮后, ...
- 14 SQLite数据库
SQLite数据库SQLite 是一款轻型的数据库SQLite 的设计目标是嵌入式的SQLite 占用资源低SQL 指结构化查询语言SQL 使我们有能力访问数据库SQL 是一种 ANSI 的标准计算机 ...
- Perl 笔试题2 -- 统计单词频次
Nvidia 2019 perl 笔试题 统计一个文件内单词的频次并排序 文本如下: "ALL happy families resemble one another; every unha ...
- UVA - 12230 Crossing Rivers(过河)(期望)
题意:从A到B需要经过n条河,已知AB间距离D和每条河的长度L以及在该条河上的船速v,求A到B平均情况下需多长时间.陆地行走速度为1,船的位置和朝向均匀随机. 分析: 1.过一条河,最短时间L/v(无 ...
- 使用Linux系统,是一种什么体验?
导读 同事,从事嵌入式软件开发多年,主要开发环境用的就是linux,最疯狂的一段时间直接把系统装成linux系统,然后在linux下面虚拟一个windows操作系统,主要有些事情必须在windows才 ...
- MFC消息映射及消息处理函数原型
MFC把消息主要分为三大类: 1. 标准Windows消息(WM_XXX) 2. 命令消息(WM_COMMAND):凡由UI对象产生的消息都是这种命令消息,可能来自菜单或加速键或工具栏按钮. 3. 控 ...
- NVIDIA TX2--3--NVIDIA Jetson TX2 查看系统版本参数状态及重要指令
NVIDIA Jetson TX2 查看系统参数状态. 当前博主的TX2更新的版本为:Jetpack 3.3, cuda 9.0.252, cudnn7.0, opencv3.3.1, TensorR ...
- 如何创建NPM包并上传
1 在NPM网站上注册,并验证(verify)自己的邮箱 https://www.npmjs.com 2 用命令行定位到你的库文件夹 3 在命令行里登录npm, 按提示依次输入用户名 密码 注册邮箱 ...