4

When I make a request to : " https://www.btcturk.com/api/orderbook " via browser or curl I get the response as expected.

When I make the same request via jersey or java libraries such as HttpsURLConnection, I get a 403 forbidden response.

I can use the same methods to make requests to any other urls running under https. An example method can be found below :

public static RestResponse getRestResponse(String url)
{   
    String jsonString;
    try
    {
        Client client = Client.create();

        WebResource webResource = client.resource(url);

        ClientResponse response = webResource.accept("application/json")
                .get(ClientResponse.class);

        if (response.getStatus() != 200) {

            return RestResponse.createUnsuccessfulResponse(response.getStatusInfo().getReasonPhrase());
        }

        jsonString = response.getEntity(String.class);
    }
    catch(Exception e)
    {
        return RestResponse.createUnsuccessfulResponse(e);
    }

    return RestResponse.createSuccessfulResponse(jsonString);
}

The above code is just to give the idea. The whole thing can be found at: https://github.com/cgunduz/btcenter/tree/master/src/main/java/com/cemgunduz/web

My network knowledge is very limited, so any directions towards where I should start would be helpful. Cheers.

Pumpkin
  • 1,993
  • 3
  • 26
  • 32

1 Answers1

0

You probably have to provide some credentials. Depending on the server configuration you have to provide either a user/password combination or a valid certificate. Try the solutions provided here: Using HTTPS with REST in Java

Community
  • 1
  • 1
Costin G.
  • 21
  • 2
  • what credential or certificate do I provide when I do : "curl https://www.btcturk.com/api/orderbook" – Pumpkin Apr 02 '14 at 10:44