小编ran*_*au5的帖子

使用OAuth-Signpost和Apache HttpComponents签署POST请求的正确方法是什么?

我目前正在使用OAuth-Signpost Java库来签署从客户端发送到实现OAuth身份验证的服务器的请求.在进行GET请求时(使用HttpURLConnection)一切正常:请求被签名,参数被包含,签名在目的地中匹配.但是,它似乎不适用于POST请求.我知道使用HttpURLConnection签名POST时可能出现的问题,因此我转移到Apache HttpComponents库以获取这些请求.我在以下示例中发送的参数是纯字符串和类似XML的字符串('rxml').我的代码如下:

public Response exampleMethod(String user, String sp, String ep, String rn, String rxml){

   //All these variables are proved to be correct (they work right in GET requests)
    String uri = "...";
    String consumerKey = "...";
    String consumerSecret = "...";
    String token = "...";
    String secret = "...";

  //create the parameters list
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("user", user));
    params.add(new BasicNameValuePair("sp", sp));
    params.add(new BasicNameValuePair("ep", ep));
    params.add(new BasicNameValuePair("rn", rn));
    params.add(new BasicNameValuePair("rxml", rxml));

   // create a consumer object and configure …
Run Code Online (Sandbox Code Playgroud)

java oauth http-post signpost apache-httpcomponents

12
推荐指数
1
解决办法
9197
查看次数

标签 统计

apache-httpcomponents ×1

http-post ×1

java ×1

oauth ×1

signpost ×1