Apache客户端http/1.1 406不可接受Java

Apache客户端http/1.1 406不可接受Java,java,api,jakarta-ee,apache-commons-httpclient,Java,Api,Jakarta Ee,Apache Commons Httpclient,我尝试在apache客户机上使用put方法。Get方法工作正常,但不知道put不工作 下面代码的输出:HTTP/1.1406不可接受 HttpClient client = new DefaultHttpClient(); HttpPut put = new HttpPut("https://securecod3.myshopify.com"); try { HashMap<String,HashMap> myMap =

我尝试在apache客户机上使用put方法。Get方法工作正常,但不知道put不工作

下面代码的输出:HTTP/1.1406不可接受

  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();
        }
HttpClient=newdefaulthttpclient();
HttpPut=新的HttpPut(“https://securecod3.myshopify.com");
试一试{
HashMap myMap=新HashMap();
HashMap值=新的HashMap();
value.put(“value”,“我们正忙着为您更新商店,一小时内就会回来。

”; value.put(“key”、“templates/index.liquid”); myMap.put(“资产”,价值); Helper hp=new Helper(); hp.convertJson(myMap); System.out.println(hp.convertJson(myMap.toString()); StringEntity se=新的StringEntity(hp.convertJson(myMap.toString(),“UTF8”); put.setEntity(se); put.setHeader(“用户代理”、“Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,类似Gecko)Chrome/58.0.3029.110 Safari/537.36”); setHeader(“内容类型”、“应用程序/json”); HttpResponse response=client.execute(put); System.out.println(“响应:+Response.getStatusLine()); List-httpHeaders=Arrays.asList(response.getAllHeaders()); System.out.println(httpHeaders); }捕获(IOE异常){ 系统输出打印ln(e); e、 printStackTrace(); }
您正在将“接受”请求头值设置为“应用程序/json”;你是想改为设置“内容类型”吗?是的,我更改了它,但仍然不工作“仍然不工作”是否意味着即使你没有设置
Accept
标题,你仍然得到“406 not Acceptable”?你确定你正在运行更新的代码?我对API一无所知,但你确定那是正确的URL吗?你遵循了什么样的参考文献来描述如何做到这一点?哦,它现在正在工作。我放了两次球。这段代码还有一个问题,我只得到状态代码,我如何获得php中的正文内容,就像我用来做这件事的“headers”=>$headers,“original_response”=>$response,“response”=>$response[1],“status”=>“0”