Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过REST通信时出现错误401_Java_Rest_Https - Fatal编程技术网

Java 通过REST通信时出现错误401

Java 通过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

我在通过一家提供商的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:password@example.com/rest/' --data 'something' --head

此外,RestTemplate还使用了jersey和HttpURLConnection,但是,结果是相同的-错误401。

通常,身份验证信息会进入头中。您确定需要在url中发送吗?供应商API需要此表单中的身份验证数据。它不支持标头中的数据访问身份验证。请尝试使用
-v
--trace
选项运行curl,以准确查看它发送的内容。我怀疑您会发现curl正在将auth数据移动到头部,而rest类则没有。