Microsoft graph API Java HTTP 客户端不允许通过补丁更新
Microsoft graph API Java HTTP client does not allow updating by patch
是否有另一种方法可以在不使用 PATCH 方法或基本 SDK 的情况下更新列表项(因为我是通过 HTTP 客户端进行的)。
public Boolean updateItem(Item i) {
if(i.getId() != null) {
String URL = "https://graph.microsoft.com/v1.0/sites/"+siteId+"/lists/"+listId+"/items/"+i.getId()+"";
try {
URL url = new URL(URL);
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.setRequestMethod("PATCH");
http.addRequestProperty("Accept", "application/json;odata.metadata=none");
http.addRequestProperty("Content-Type", "application/json");
http.setRequestProperty("Authorization", "Bearer "+getAuth());
http.setDoOutput(true);
http.setDoInput(true);
send(http.getOutputStream(), i.toJson());
http.connect();
if(http.getResponseCode() == 200) {
String content = read(http.getInputStream());
System.out.println(content);
return true;
}else {
String errorContent = read(http.getErrorStream());
System.out.println("UPDATE ITEM ERROR:"+errorContent);
}
}catch(IOException e) {
System.out.println("UPDATE ITEM (IOException):"+e.getMessage());
}
}
return false;
}
getAuth() returns 一个有效的访问令牌。
我试过这个:
http.setRequestProperty("X-HTTP-Method-Override", "PATCH");
然而微软似乎只承认它为POST
已解决。我使用 Apaches HTTP Client 来做补丁方法(org.apache.http.client.methods.*)。
是否有另一种方法可以在不使用 PATCH 方法或基本 SDK 的情况下更新列表项(因为我是通过 HTTP 客户端进行的)。
public Boolean updateItem(Item i) {
if(i.getId() != null) {
String URL = "https://graph.microsoft.com/v1.0/sites/"+siteId+"/lists/"+listId+"/items/"+i.getId()+"";
try {
URL url = new URL(URL);
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.setRequestMethod("PATCH");
http.addRequestProperty("Accept", "application/json;odata.metadata=none");
http.addRequestProperty("Content-Type", "application/json");
http.setRequestProperty("Authorization", "Bearer "+getAuth());
http.setDoOutput(true);
http.setDoInput(true);
send(http.getOutputStream(), i.toJson());
http.connect();
if(http.getResponseCode() == 200) {
String content = read(http.getInputStream());
System.out.println(content);
return true;
}else {
String errorContent = read(http.getErrorStream());
System.out.println("UPDATE ITEM ERROR:"+errorContent);
}
}catch(IOException e) {
System.out.println("UPDATE ITEM (IOException):"+e.getMessage());
}
}
return false;
}
getAuth() returns 一个有效的访问令牌。
我试过这个:
http.setRequestProperty("X-HTTP-Method-Override", "PATCH");
然而微软似乎只承认它为POST
已解决。我使用 Apaches HTTP Client 来做补丁方法(org.apache.http.client.methods.*)。