首页 > 解决方案 > Apache 客户端 http/1.1 406 不可接受 Java

问题描述

我尝试将 put 方法与 apache 客户端一起使用。Get 方法工作正常,但不知道 put 不起作用。

我的以下代码的输出:HTTP/1.1 406 Not Acceptable

  HttpClient client = new DefaultHttpClient();
        HttpPut put = new HttpPut("https://securecod3.myshopify.com");

        try {
            HashMap<String,HashMap> myMap = new HashMap<>();
            HashMap<String,String> value = new HashMap<>();
            value.put("value","<img src='Javacode.png'><p>We are busy updating the store for you and will be back within the hour.</p>");
            value.put("key","templates/index.liquid");
            myMap.put("asset",value);
            Helper hp = new Helper();
            hp.convertJson(myMap);
            System.out.println(hp.convertJson(myMap).toString());


            StringEntity se =   new StringEntity(hp.convertJson(myMap).toString(),"UTF8");
            put.setEntity(se);
            put.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
            put.setHeader("Content-Type", "application/json");
            HttpResponse response = client.execute(put);
            System.out.println("Response: " + response.getStatusLine());
            List<Header> httpHeaders = Arrays.asList(response.getAllHeaders());
                    System.out.println(httpHeaders);

        } catch (IOException e) {
            System.out.println(e);
            e.printStackTrace();
        }

标签: javaapijakarta-eeapache-commons-httpclient

解决方案


推荐阅读