我正在创建一个Spring Boot应用程序,我想通过rest api创建一个交换:
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
String auth = "guest:guest";
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")) );
String authHeader = "Basic " + new String( encodedAuth );
headers.set( "Authorization", authHeader );
String uri = "http://localhost:15672/api/exchanges/%2f/my-new-exchange-new";
String input = "{\"type\":\"direct\",\"durable\":\"true\"}";
HttpEntity<String> entity = new HttpEntity<String>(input,headers);
ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.PUT, entity, String.class);
System.out.println(response);
但是我总是得到错误:
PUT request for "http://localhost:15672/api/exchanges/%252f/my-new-exchange-new" resulted in 404 (Not Found); invoking error handler
你可以帮我一个提示吗?谢谢!
如果您需要,可以尝试一下:https://github.com/pkid/rabbittest
答案 0 :(得分:1)
问题很可能是错误中返回的ParseObject.pinAllInBackground(objects);
chart.xScale(d3.time.scale())
应用于uri
变量的网址编码。为避免这种情况,您需要使用与RestTemplate
一起使用的%252f
方法,并告诉它假设网址已经编码:
RestTemplate