Java Spring Boot:基本身份验证,但在Postman中有效
我正在尝试使用基本身份验证使用安全API,但我不断返回401错误。问题是使用Postman时凭据和请求的URL连接成功。这是我正在打的电话,不确定我是否遗漏了什么:Java Spring Boot:基本身份验证,但在Postman中有效,java,spring,spring-boot,Java,Spring,Spring Boot,我正在尝试使用基本身份验证使用安全API,但我不断返回401错误。问题是使用Postman时凭据和请求的URL连接成功。这是我正在打的电话,不确定我是否遗漏了什么: public ResponseEntity randomSht(){ String username = "APIKEY"; String password = ":PASSWORD"; HttpHeaders headers = new HttpHeaders(); hea
public ResponseEntity randomSht(){
String username = "APIKEY";
String password = ":PASSWORD";
HttpHeaders headers = new HttpHeaders();
headers.setBasicAuth(username, password);
// request url
String url = "https://test.myshopify.com/admin/orders/2013413015622.json";
RestTemplate restTemplate = new RestTemplate();
HttpEntity request = new HttpEntity(headers);
ResponseEntity<String> response = restTemplate.exchange(
url, HttpMethod.GET, request, String.class);
System.out.println(response);
return response;
}
public ResponseEntity randomSht(){
字符串username=“APIKEY”;
字符串password=“:password”;
HttpHeaders=新的HttpHeaders();
headers.setBasicAuth(用户名、密码);
//请求url
字符串url=”https://test.myshopify.com/admin/orders/2013413015622.json";
RestTemplate RestTemplate=新RestTemplate();
HttpEntity请求=新的HttpEntity(标头);
ResponseEntity response=restemplate.exchange(
url,HttpMethod.GET,请求,String.class);
System.out.println(响应);
返回响应;
}
也许你的密码只是密码
,你不需要添加:
,如果这只是标题名和值之间的偏差。也许你的密码只是密码
,如果这只是标题名和值之间的偏差,你不需要添加: