你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中有特殊字符怎么处理?的更多相关文章

  1. URLEncode解决url中有特殊字符的问题

      问题:图片上传后的url地址中有&等特殊字符,页面传到后端时被自动处理成了&   解决:前端对url进行URLEncode,后端收到后进行URLDecode   总结:需要在请求u ...

  2. MVC 记录操作日志与过滤特殊字符

    最近进行的MVC系统需要用到记录操作日志和过滤特殊字符的功能,如果每个action中都调用记录日志的方法就太麻烦了,所以根据需要结合mvc的过滤机制 写了个特殊字符验证与记录操作日志的公用类: pub ...

  3. curl 下载地址中有特殊字符解决方案

    curl 下载地址中有特殊字符解决方案 情况 使用 curl 下载 地址中带有 特殊字符的时候 比如下面这个地址.实际访问地址不正确,参数丢失问题 curl -o kspf.jpeg https:// ...

  4. 网址URL中特殊字符转义编码

    网址URL中特殊字符转义编码字符 - URL编码值空格 - %20" - %22# - %23% - %25& - %26( - %28) - %29+ - %2B, - %2C/ ...

  5. Tomcat8升级后URL中特殊字符报错出现原因

    请求带上花括号等字符,请求无法送达服务端,报错: Failed to load resource: the server responded with a status of 400 () https ...

  6. URL传值特殊字符处理

    问题:url传递的值中有特特殊字符,比如"<"或者">"会导致传递的参数被截短,也就是特殊字符之后的值传递不过去(例如:var list=" ...

  7. Mysql删除表名中有特殊字符的表

    由于公司业务和应用的调整,之前在Mysql中的很多表都不需要了,故需要对数据库进行整理.   刚开始,我在想:不就删除一些表吗?很好解决,写个简单的脚本就可以了.我先看了数据库中有80000多个表,很 ...

  8. 033 Url中特殊字符的处理

    在url跳转页面的时候,参数值中的#不见了,一直没有处理,今天有空看了一下,后来发现后台的过滤器之类的都没有处理,就比较奇怪了,原来是特殊字符的问题. 一:Url中的特殊字符 1.说明 这里还是需要做 ...

  9. js中有特殊字符的编码格式

    在get和post方法中,如果传入的参数值有特殊字符,如:“&”,在get中的url需要拼接,可以使用encodeURICompontent来编码来转化 回调就是在上面传递实际参数,传递给aj ...

随机推荐

  1. HTML学习第二天

    HTML学习第二天 今天学的比较少,有些乱,先只写一个知识点 三种样式表插入方式 外部样式表: <link rel="stylesheet" type="text/ ...

  2. git仓库拆分

    例如: # 这就是那个大仓库 big-project $ git clone git@github.com:tom/big-project.git $ cd big-project # 把所有 `co ...

  3. Springboot Bean循环依赖问题

    参考博客原文地址: https://www.jb51.net/article/168398.htm https://www.cnblogs.com/mianteno/p/10692633.html h ...

  4. 133-PHP子类无法重写父类private同名函数

    <?php class father{ //定义father类 //定义protected成员方法 protected function cook(){ return 'protected co ...

  5. 087-把PHP数组中的元素按随机顺序重新排列shuffle

    <?php $arr=array(3,23,'A','f','123','hello'); //定义一个数组 echo '排序之前的数组信息:<br>'; print_r($arr) ...

  6. JQuery 多属性选择节点

    JQuery 1.6.0+以后用prop()代替attr(); 多属性选择节点 $("input[type=checkbox][name='first2'][value='first4']& ...

  7. 腾讯云服务器上搭建 2.176.3-1.1 版本的Jenkins,jdk 11

    [root@VM_0_12_centos fonts]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [root@VM_0 ...

  8. Django实现websocket

    django实现websocket大致上有两种方式,一种channels,一种是dwebsocket.channels依赖于redis,twisted等 一 dwebsocket 1 Django实现 ...

  9. python转换ascii码

    字符转数字 ord("A") 数字转字符 chr(65)

  10. 面向对象-static关键字实战案例

    面向对象-static关键字实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.static关键字概述 1>.static的功能 static关键字用于修饰成员变量和 ...