能否请您解释一下此API中使用的路径变量? deviceCompliancePolicyId deviceComplianceDeviceStatusId。
这是我的示例代码
private static String patchComplianceCheckh(String accessToken) throws IOException {
String s1 = "https://graph.microsoft.com/v1.0/deviceManagement/deviceCompliancePolicies/71889b5c-8ea2-473c-9a95-23bcd0e15ae8/deviceStatuses/2fa7d8fe-f410-4872-9991-87092a6ac070";
URL url = new URL(s1);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("X-HTTP-Method-Override", "PATCH");
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "Bearer " + accessToken);
conn.setRequestProperty("Authorization", "Bearer " + accessToken);
// conn.setRequestProperty("Accept","application/json");
conn.setRequestProperty("Content-type","application/json");
int httpResponseCode = conn.getResponseCode();
System.out.println("httpResponseCode " + httpResponseCode);
if(httpResponseCode == 200) {
BufferedReader in = null;
StringBuilder response;
try{
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
} finally {
in.close();
}
System.out.println(response.toString());
return response.toString();
} else {
return String.format("Connection returned HTTP code: %s with message: %s",
httpResponseCode, conn.getResponseMessage());
}
}
如何将请求参数发送给请求?我收到411 HTTP错误代码。
答案 0 :(得分:0)
DeviceCompliancePolicyId
在通话下方进行-
GET https://graph.microsoft.com/v1.0/deviceManagement/deviceCompliancePolicies
在下面的响应中返回的ID(“ id”:“ 4214b716-b716-4214-16b7-144216b71442”)是DeviceCompliancePolicyId-
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 393
{
"value": [
{
"@odata.type": "#microsoft.graph.deviceCompliancePolicy",
"id": "4214b716-b716-4214-16b7-144216b71442",
"createdDateTime": "2017-01-01T00:02:43.5775965-08:00",
"description": "Description value",
"lastModifiedDateTime": "2017-01-01T00:00:35.1329464-08:00",
"displayName": "Display Name value",
"version": 7
}
]
}
DeviceComplianceDeviceStatusId
在通话下方进行-
GET https://graph.microsoft.com/v1.0/deviceManagement/deviceCompliancePolicies/{deviceCompliancePolicyId}/deviceStatuses
在下面的响应中返回的ID(“ id”:“ c6c78124-8124-c6c7-2481-c7c62481c7c6”)是DeviceComplianceDeviceStatusId-
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 544
{
"value": [
{
"@odata.type": "#microsoft.graph.deviceComplianceDeviceStatus",
"id": "c6c78124-8124-c6c7-2481-c7c62481c7c6",
"deviceDisplayName": "Device Display Name value",
"userName": "User Name value",
"deviceModel": "Device Model value",
"complianceGracePeriodExpirationDateTime": "2016-12-31T23:56:44.951111-08:00",
"status": "notApplicable",
"lastReportedDateTime": "2017-01-01T00:00:17.7769392-08:00",
"userPrincipalName": "User Principal Name value"
}
]
}