我试图在Apache客户端上使用put方法。 Get方法可以正常工作,但不知道put不能正常工作。
我的以下代码的输出:HTTP / 1.1 406不可接受
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();
}