使用令牌 API 的 WSO2 令牌生成失败
WSO2 token generation using Token API failing
我正在使用 WSO2-AM-1.9.0,尝试使用 Consumer Key 和 Consumer Secret 生成访问令牌。
使用 CURL 进行调用时它工作正常
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 时,它 returns 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");
我正在使用 WSO2-AM-1.9.0,尝试使用 Consumer Key 和 Consumer Secret 生成访问令牌。 使用 CURL 进行调用时它工作正常
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 时,它 returns 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");