2

I'm using OAuth-Signpost 1.2 to authenticate requests to a Magento RESTful application.

GET requests were pretty easy to implement using simply HttpURLConnection, but, so far as I understand, for POST requests I'd have to also use a library like Apache HttpComponents HttpClient. However, I'm not being able to figure out the right way to do so.

My current code is as follows:

public static void try2(OAuthConsumer consumer , String API_URL, String postInput) throws Exception{
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost postRequest = new HttpPost(API_URL);

    try {
        StringEntity input = new StringEntity(postInput);
        input.setContentType("application/json");
        postRequest.setEntity(input);
        consumer.sign(postRequest);

        HttpResponse response = httpClient.execute(postRequest);

        if (response.getStatusLine().getStatusCode() != 201) {
            System.out.println("Failure. Code: " + response.getStatusLine().getStatusCode());
        }

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

But all I get is an error 500.

In a more general way my question would be: how can I sign POST requests to a RESTful app using signpost?

Liadz
  • 51
  • 5
  • Can you look into the server logs for details of the 500 error? –  Sep 28 '12 at 06:48
  • @Tichodroma: If you are talking about the error.log file of my app/site there's nothing regarding any OAuth operation nor any error reported after September 18th (and since I got these errors yesterday...). In the access.log file though I've found lines like this: `127.0.0.1 - - [28/Sep/2012:00:44:59 -0300] "POST /api/rest/customers HTTP/1.1" 500 260 "-" "Apache-HttpClient/4.2.1 (java 1.5)"` but that's all regarding error 500. – Liadz Sep 29 '12 at 00:19

0 Answers0