我尝试在项目中使用Restful
连接到webservice
OkHttpClient
。
这里是webservice
URL ,
{base-uri}/v2/customers? nic={nic}&passport={passport}®istrationNumber={registrationNumber}
然后我用OkHttpClient
连接了这个webservice
。这是我的代码段,
OkHttpClient client = new OkHttpClient();
HttpUrl url = new HttpUrl.Builder()
.scheme("http")
.host("192.168.16.50")
.port(8092)
.addPathSegment("v2")
.addPathSegment("customers")
.addQueryParameter("nic", nic)
.build();
Request request = new Request.Builder()
.url(url)
.addHeader("Authorization", "Bearer Rg_i7rWCQ0U-4enB-yD5T3ksPRrHS9c")
.addHeader("ChannelId", "1000000000")
.addHeader("RequestId", "898989")
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
Call call = client.newCall(request);
try {
Response response = call.execute();
LOGGER.info("Response : " + response);
List<String> outputJSONObjects = IOUtils.readLines(response.body().byteStream());
status = response.message();
statusCode = response.code();
LOGGER.info("satatus======================>>>" + status);
LOGGER.info("statusCode======================>>>" + statusCode);
ObjectMapper mapper = new ObjectMapper();
for (String jsOut : outputJSONObjects) {
JsonNode jsObj = mapper.readTree(jsOut);
dao = mapper.treeToValue(jsObj, ResultCustomerInformationDao.class);
}
} catch (Exception e) {
LOGGER.error(e);
}
执行此代码后,出现以下错误,
java.net.SocketTimeoutException: connect timed out
你有什么主意吗?