我正在尝试开发一个客户端程序,该程序通过 azure 创建设备标识。我使用 azure rest 来创建它,所以我使用 jersey 实现从客户端程序调用这个 web 服务,但我得到错误com.sun.jersey.api.client.ClientHandlerException: java.net.SocketException: Socket is not connected: connect 我使用测试它邮递员可以工作,而python可以工作。这是我的java代码:
public class Test {
public static void main(String[] args) {
try {
Client client = Client.create();
WebResource webResource = client
.resource("https://xxxx-iot-hub.azure-devices.net/devices");
ClientResponse response = webResource.path("/iotdevice1").queryParam("top", "100").queryParam("api-version", "2016-02-03").header("Content-Type", "application/json")
.header("Authorization", "SharedAccessSignature sr=xxxxx-iot-hub.azure-devices.net&sig=Yxxxxxxxxxx=1497357420&skn=iothubowner")
.put(ClientResponse.class);
String output = response.getEntity(String.class);
System.out.println("Output from Server .... \n");
System.out.println(output);
} catch (Exception e) {
e.printStackTrace();
}
}
}
谢谢