泽西岛的卷曲令牌请求等价物
Posted
技术标签:
【中文标题】泽西岛的卷曲令牌请求等价物【英文标题】:Curl token request equivalent in Jersey 【发布时间】:2016-01-25 20:34:39 【问题描述】:我知道这个问题已经被问了一百万次,但我无法弄清楚我的令牌请求出了什么问题。
curl中的命令是
curl -v -X POST -H "授权:基本 XXXXXXXXXXXXXXXXXXXXXX" -H “内容类型:应用程序/x-www-form-urlencoded;charset=UTF-8”-k -d “grant_type=密码&用户名=XXXXX&密码=XXXXX” https://localhost/sso/token
转换成球衣应该是:
Client client = Client.create();
WebResource webResource = client.resource("https://localhost/sso/token");
String appKey= "Basic XXXXXXXXXXXXXXXXXXXXXX"
String input="grant_type=password&username=XXXXX&password=XXXXX";
ClientResponse response = null;
response = webResource.
header("Authorization", appKey).
header("Content-Type", "/x-www-form-urlencoded;charset=UTF-8").
accept("application/json").
post(ClientResponse.class, input);
if (response.getStatus() != 200)
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
String output = response.getEntity(String.class);
System.out.println("Server response .... \n");
System.out.println(output);
catch (Exception e)
e.printStackTrace();
**
我得到的答案:
java.lang.RuntimeException: 失败: HTTP 错误代码: 415 at com.javacodegeeks.enterprise.rest.jersey.jerseyclient.JerseyClientAccessToken.main(JerseyClientAccessToken.java:67)
谁能告诉我我做错了什么?
【问题讨论】:
【参考方案1】:这个:
header("Content-Type", "application/json;charset=UTF-8");
和这个不一样:
Content-Type: "application/x-www-form-urlencoded;charset=UTF-8"
所以你应该改变它。这就是您收到 415 错误(不支持的媒体类型)的原因。
【讨论】:
以上是关于泽西岛的卷曲令牌请求等价物的主要内容,如果未能解决你的问题,请参考以下文章