我試圖通過REST服務從shopify API獲取產品記錄。但我得到這個錯誤{"errors":{"product":"can't be blank"}}
下面是代碼片段。Java Servlet如何從Shopify API獲取json響應
String getURL = "https://myshop.myshopify.com/admin/products.json";
url = new URL(getURL);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type",
"application-json");
connection.setRequestProperty("X-Shopify-Access-Token",token);
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
// Send request
DataOutputStream w = new DataOutputStream(
connection.getOutputStream());
w.flush();
w.close();
// Get Response
InputStream i = connection.getInputStream();
BufferedReader streamReader = new BufferedReader(new InputStreamReader(i, "UTF-8"));
StringBuilder responseStrBuilder = new StringBuilder();
String inputStr;
while ((inputStr = streamReader.readLine()) != null){
System.out.println(inputStr);
responseStrBuilder.append(inputStr);
}
錯誤信息提示你是不是通過在您需要的產品信息產品ID /密碼。看起來像期待在請求中輸入一些內容。 – sudmong 2013-05-08 11:05:20
它應該是沒有必要的參數,因爲如果我直接粘貼到瀏覽器的url它可以訪問 – user236501 2013-05-08 11:50:40