Java 通过REST通信时出现错误401
我在通过一家提供商的REST服务进行通信时遇到问题。不幸的是,我得到一个未经授权的HTTP 401Java 通过REST通信时出现错误401,java,rest,https,Java,Rest,Https,我在通过一家提供商的REST服务进行通信时遇到问题。不幸的是,我得到一个未经授权的HTTP 401 RestTemplate rest = new RestTemplate(); rest.postForObject("https://login:password@example.com/rest/", arg, responseType); 使用curl对相同数据(登录名和密码)的请求工作正常,并返回HTTP 200 curl --request POST 'https://login:pa
RestTemplate rest = new RestTemplate();
rest.postForObject("https://login:password@example.com/rest/", arg, responseType);
使用curl对相同数据(登录名和密码)的请求工作正常,并返回HTTP 200
curl --request POST 'https://login:password@example.com/rest/' --data 'something' --head
此外,RestTemplate还使用了jersey和HttpURLConnection,但是,结果是相同的-错误401。通常,身份验证信息会进入头中。您确定需要在url中发送吗?供应商API需要此表单中的身份验证数据。它不支持标头中的数据访问身份验证。请尝试使用
-v
或--trace
选项运行curl,以准确查看它发送的内容。我怀疑您会发现curl正在将auth数据移动到头部,而rest类则没有。