使用令牌API失败的WSO2令牌生成

时间:2015-08-28 07:09:20

标签: wso2 wso2-am

我正在使用WSO2-AM-1.9.0,试图使用Consumer Key和Consumer Secrete生成Access令牌。 使用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时,它会返回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中找不到匹配的资源                  

对此有任何帮助和信息表示赞赏。

1 个答案:

答案 0 :(得分:0)

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

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