开发者

OAuth with Signpost and Apache Commons HTTP

开发者 https://www.devze.com 2023-02-13 06:01 出处:网络
So I\'m working with the Signpost OAuth library for Java. I\'m running into some complications using the Apache Commons HTTP library with it. Take a look at the following code:

So I'm working with the Signpost OAuth library for Java. I'm running into some complications using the Apache Commons HTTP library with it. Take a look at the following code:

URL url = new URL("http://api.neoseeker.com/forum/get_pm_counts.json");
HttpRequest request = (HttpRequest) url.openConnection();

consumer.sign(request);

request.connect();

System.out.println("Response: " + request.getResponseCode() + " "
        + request.getResponseMessage());

This is taking from this example. You can see that request used to be a HttpURLConnection, but because I'll be using the Apache Commons HTTP library, I changed it to a HttpRequest object. Now, I'm getting errors when I call connect(), g开发者_如何转开发etResponseCode(), and getResponseMessage(), because those functions are for a HttpURLConnection. What functions from HttpRequest would I use so I can get the code to compile and run correctly? Thanks!


Signpost has a seperate module for using Apache's HTTP client. You need to use a CommonsHttpOAuthConsumer for this.

This module lives here - http://code.google.com/p/oauth-signpost/downloads/detail?name=signpost-commonshttp4-1.2.1.1.jar&can=2&q=

Some sample code to use it is here - http://code.google.com/p/oauth-signpost/wiki/ApacheCommonsHttp4, but it just comes down to instantiating a CommonsHttpOAuthConsumer instead of the normal one...

If you use maven, the coordinates are here, I couldn't find them documented anywhere when I was trying to figure this out...

<dependency>
    <groupId>oauth.signpost</groupId>
    <artifactId>signpost-commonshttp4</artifactId>
    <version>1.2.1.1</version>
</dependency>
0

精彩评论

暂无评论...
验证码 换一张
取 消