I am trying to do a PUT request call from code. I have used WebResource Class object like below:
final Client client = Client.create();
final WebResource webResource = client.resource(API_URL);
client.setConnectTimeout(Integer.valueOf(connectionTimeout));
client.setReadTimeout(Integer.valueOf(readTimeout));
client.addFilter(new HTTPBasicAuthFilter(apiUsername, apiPassword));
webResource.type(MediaType.APPLICATION_JSON);
webResource.accept(MediaType.APPLICATION_JSON);
webResource.header("Content-Length",
String.valueOf(jsonInString.getBytes(Charset.forName("UTF-8")).length));
final ClientResponse response = webResource.put(ClientResponse.class,
jsonInString);
here all the variables connectionTimeout, readTimeout, apiUsername, apiPassword, API_URL has proper values.
From the very last line it is trowing a SocketException as com.sun.jersey.api.client.ClientHandlerException: java.net.SocketException: Connection reset The Exception is caught within ClientHandlerException catch block.
But when I am trying to hit the API_URL with other inputs from Postman Rest Client, I am geting success response.
Can anyone please help me understand why it is not working from code?
答案 0 :(得分:0)
使用JRE 7作为运行时环境。并创建您的客户端,如下所示并使用。它会解决你的问题。
AdminSubscriptionViewModel vm = new AdminSubscriptionViewModel()
{
subscriptions = new tbl3PSubscriptions()
};
vm.subscriptions.DayOfWeek = "MON";