0

我试图通过 REST 服务从 shopify API 获取产品记录。但是我收到了这个错误{"errors":{"product":"can't be blank"}}下面是代码片段。

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

1 回答 1

0

请求标头应该是这样的:

connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json");
于 2013-05-08T11:03:09.403 回答