2014-01-22 166 views
4

當我通過瀏覽器或curl向「https://www.btcturk.com/api/orderbook」發出請求時,我得到預期的響應。https請求返回403

當我通過jersey或java庫(如HttpsURLConnection)發出相同的請求時,我得到一個403禁止響應。

我可以使用相同的方法向https下運行的任何其他URL發出請求。一種示例性方法可以在下面找到:

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); 
} 

上面的代碼只是給的想法。整個事情可以在:https://github.com/cgunduz/btcenter/tree/master/src/main/java/com/cemgunduz/web

我的網絡知識是非常有限的,所以任何方向,我應該開始將是有益的。乾杯。

回答

0

您可能需要提供一些憑證。根據服務器配置,您必須提供用戶/密碼組合或有效證書。試試這裏提供的解決方案: Using HTTPS with REST in Java

+0

當我這樣做時,我提供了什麼憑證或證書:「curl https://www.btcturk.com/api/orderbook」 – Pumpkin