我是新來的azure iot。我正嘗試在Azure iot hub中使用其餘api創建共享訪問策略。使用Rest API在Azure IoT Hub中創建共享訪問策略
https://management.azure.com/subscriptions/{subscription-Id}/resourceGroups/{group-name}/providers/Microsoft.Devices/IotHubs/{hub-name}?api-version=2016-02-03");
和我的Java代碼
String policyold = "{\"tags\" : {}, \"location\": \"East Asia\",\"properties\" : \"authorizationPolicies\" : [{\"name\" : \"policy-namw\", \"primaryKey\" : \"{mykey}\" ,\"secondaryKey\" : \"secondary-key\" ,\"permissions\" :[\"ServiceConnect\" ,\"RegistryRead\" ,\"RegistryWrite\" ,\"DeviceConnect\"]}],\"eventHubEndpoints\" : { \"events\" : {\"messageRetentionInDays\":\"2\"}}}";
StringEntity input1 = new StringEntity(policyold);
input1.setContentType("application/json");
input1.setContentEncoding("UTF8");
put.setEntity(input1);
put.setHeader("Authorization", token);
HttpResponse r2 = httpclient2.execute(put);
System.out.println(r2.getStatusLine());
String content2 = EntityUtils.toString(r2.getEntity());
org.json.JSONObject recvObj2 = new org.json.JSONObject(content2);
,但我面臨的followiing錯誤。
HTTP/1.1 400 Bad Request {"error":{"code":"InvalidRequestContent","message":"The request content was invalid and could not be deserialized: 'Error converting value \"authorizationPolicies\" to type 'System.Collections.Generic.Dictionary`2[System.String,Newtonsoft.Json.Linq.JToken]'. Path 'properties', line 1, position 76.'."}}
此外,我正在使用本教程。 https://msdn.microsoft.com/en-us/library/mt589015.aspx
任何人都可以幫助我解決這個問題嗎?
我建議您可以查看Azure IoT中心Java SDK以簡化API調用。鏈接是在https://github.com/Azure/azure-iot-sdks/tree/master/java – juvchan
是的,我試圖用它來創建共享訪問策略。但找不到任何代碼示例和文檔用於此目的。這就是爲什麼我結束了HTTP休息API。你可以參考一個嗎?謝謝 – Sadaf