I am attempting to write a private app for the Shopify API in Java. I’m using the org.apache.http library to write my requests. Below is my current request:
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;
This is returning an HTML page asking for login. After searching the Shopify forums, it appears that when doing POST or PUT requests to Shopify, you’re not allowed to send any cookies otherwise the login page is returned. So my question is, is there any way to ensure that CloseableHttpClient will NOT send any cookies?
2
Answers
You can bind a custom Cookie store to a local HTTP Context and send that in the request
One way of stopping HttpClient from sending cookies to the target host is, well, by disabling cooking management