你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. linux下anaconda的安装和使用

    1.将python3设置为默认 直接执行这两个命令即可: sudo update-alternatives --install /usr/bin/python python /usr/bin/pyth ...

  2. 2.15 使用web 编写一个简单记事本

    首先陈列问题  (等待解决): 1. 界面是使用 H5   iframe 标签合并而成的,当窗口化之后点击任务栏,显示的内容会在任务栏的下边 希望可以找其他方式替代 (其他方法不熟练,不能应用) 如图 ...

  3. jQuery获取display为none的隐藏元素的宽度和高度的解决方案

    1.利用给元素添加行内样式:visibility:hidden;display:block 2.让隐藏元素变成有物理尺寸存在,但不可见,获取元素宽高 3.再给它还原成display为none,去除vi ...

  4. Centos7.4 Storm2.0.0 + Zookeeper3.5.5 高可用集群搭建

    想了下还是把kafka集群和storm集群分开比较好 集群规划: Nimbus Supervisor storm01 √ √ storm02 √(备份) √ storm03 √ 准备工作 老样子复制三 ...

  5. sublime text快速运行浏览web/html页面

    安装View In Browser插件 快捷键 Ctrl+Shift+P(菜单栏Tools->Command Paletter),输入 pcip选中Install Package并回车,输入Vi ...

  6. JS笔记03

    JS图片库 标记 需求效果: 网页中的图片链接显示在网页中的图片框内部而不是打开新的页面 //html部分 <!DOCTYPE html> <html> <head> ...

  7. (排序EX)P1583 魔法照片

    题解: 需要注意的是,快排完之后并不是按照编号从小到大的顺序输出 #include<iostream>using namespace std;int r=0;void swap(int & ...

  8. 【LeetCode】电话号码的字母组合

    [问题]给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:" 输出:["ad ...

  9. Day2-T4

    原题目 当然这是原题+,要输路径的.所以必须DFS. Describe:DP or DFS code: #include<bits/stdc++.h> using namespace st ...

  10. 16 react 发送异步请求获取数据 和 使用Redux-thunk中间件进行 ajax 请求发送

    1.发送异步请求获取数据 1.引入 axios ( 使用 yarn add axios 进行安装 ) import axios from 'axios'; 2. 模拟 在元素完成挂载后加载数据 并初始 ...