2015-08-28 111 views
1

我正在使用WSO2-AM-1.9.0,尝试使用使用者密钥和消费者密钥生成访问令牌。 使用curl拨打呼叫时,它工作正常使用令牌API失败的WSO2令牌生成

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中发现任何帮助和信息理解给定请求

匹配的资源。

回答

0

您必须发送POST请求而不是GET。使用,

HttpPost httpPost = new HttpPost("http://10.0.100.108:8280/token"); 
+0

它的工作 非常感谢Sajith的帮助。 –