【发布时间】:2018-01-05 06:26:54
【问题描述】:
我正在尝试用 Java 为 Shopify API 编写一个私有应用程序。我正在使用 org.apache.http 库来编写我的请求。以下是我目前的要求:
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()).build();
HttpPut putRequest = new HttpPut(request);
StringEntity params;
try {
params = new StringEntity(json);
putRequest.addHeader("X-Shopify-Access-Token", Constants.getShopifySharedSecret());
putRequest.setEntity(params);
CloseableHttpResponse response = httpClient.execute(putRequest);
HttpEntity entity = response.getEntity();
System.out.println("Title Change Request Output: ");
System.out.println(EntityUtils.toString(entity));
response.close();
httpClient.close();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return;
这将返回一个要求登录的 HTML 页面。在搜索 Shopify 论坛后,似乎在向 Shopify 发出 POST 或 PUT 请求时,您不允许发送任何 cookie,否则会返回登录页面。所以我的问题是,有什么办法可以确保 CloseableHttpClient 不会发送任何 cookie?
【问题讨论】:
标签: java cookies http-headers shopify apache-httpclient-4.x