首页 文章

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

提问于
浏览
1

我正在使用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

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

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

相关问题