使用令牌API生成WSO2令牌失败
我正在使用WSO2-am-1.9.0,试图使用使用者密钥和使用者机密生成访问令牌。 使用CURL打电话时,效果很好使用令牌API生成WSO2令牌失败,wso2,wso2-am,Wso2,Wso2 Am,我正在使用WSO2-am-1.9.0,试图使用使用者密钥和使用者机密生成访问令牌。 使用CURL打电话时,效果很好 curl -k -d "grant_type=password&username=testuser1&password=testUser1&scope=SANDBOX" -H "Content-Type:application/x-www-form-urlencoded" -H "Authorization:Basic ZXNuaHJTZmJmOW9
curl -k -d "grant_type=password&username=testuser1&password=testUser1&scope=SANDBOX" -H "Content-Type:application/x-www-form-urlencoded" -H "Authorization:Basic ZXNuaHJTZmJmOW9XS28xTVM5UHJSZ1BacUU0YTpld040RGh1ZmsxYTNZbndVNU1uMVlGM3IwanNh" http://10.0.100.108:8280/token
但是当尝试使用Java时,它返回403错误代码。代码是:
try
{
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://10.0.100.108:8280/token");
HttpParams params=new BasicHttpParams();
get.addHeader("Authorization","Basic ZXNuaHJTZmJmOW9XS28xTVM5UHJSZ1BacUU0YTpld040RGh1ZmsxYTNZbndVNU1uMVlGM3IwanNh");
get.addHeader("content-type", "application/x-www-form-urlencoded");
params.setParameter("grant_type", "password");
params.setParameter("username", "testuser1");
params.setParameter("password", "testUser1");
params.setParameter("scope", "SANDBOX");
get.setParams(params);
HttpResponse response = client.execute(get);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
responseBody = responseBody +"\n"+line;
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
错误:
403状况报告
运行时错误在API中找不到与给定请求匹配的资源
非常感谢您提供的任何帮助和信息。您必须发送POST请求,而不是GET。使用
HttpPost httpPost = new HttpPost("http://10.0.100.108:8280/token");
你必须发送一个POST请求,而不是GET。使用
HttpPost httpPost = new HttpPost("http://10.0.100.108:8280/token");