3

Im making api call with postman on url:

https://cex.io/api/order_book/BTC/USD

plain GET no headers no params no nothing. But the same with java:

RestTemplate rt = new RestTemplate();
rt.getForObject("https://cex.io/api/order_book/BTC/USD", String.class);

gets me 403. where is the problem?

Juan Carlos Mendoza
  • 5,736
  • 7
  • 25
  • 50
filemonczyk
  • 1,613
  • 5
  • 26
  • 47

1 Answers1

10

RestTemplate sets "User-Agent: Java_version" header, and it seems the site you are trying to query denies access with that user-agent.

You can explicitly set a user-agent instead of the default one like:

    HttpHeaders headers = new HttpHeaders();
    headers.set("User-agent", "SomeUserAgent");
    HttpEntity<String> entity = new HttpEntity<String>(headers);

    RestTemplate rt = new RestTemplate();
    String result = rt.exchange("https://cex.io/api/order_book/BTC/USD", HttpMethod.GET, entity, String.class).getBody();
helospark
  • 1,420
  • 9
  • 12