OAuth with Signpost and Apache Commons HTTP

So, I am working with the Signpost OAuth library for Java. I am facing 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 a take from this example . You can see that request used as an HttpURLConnection , but since I will use the Apache Commons HTTP library, I changed it to an HttpRequest object. Now I get errors when I call connect() , getResponseCode() and getResponseMessage() because these functions are for HttpURLConnection . What functions from HttpRequest would I use so that I can get the code to compile and run correctly? Thanks!

+4
source share
1 answer

Signpost has a separate module for using the Apache HTTP client. For this you need to use CommonsHttpOAuthConsumer.

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 here is http://code.google.com/p/oauth-signpost/wiki/ApacheCommonsHttp4 , but it just comes down to creating an instance of CommonsHttpOAuthConsumer instead of the usual ...

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

 <dependency> <groupId>oauth.signpost</groupId> <artifactId>signpost-commonshttp4</artifactId> <version>1.2.1.1</version> </dependency> 
+6
source

Source: https://habr.com/ru/post/1341061/


All Articles