我试图通过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