休息Web服务连接超时

时间:2018-10-26 04:28:25

标签: java rest okhttp

我尝试在项目中使用Restful连接到webservice OkHttpClient

这里是webservice URL

{base-uri}/v2/customers? nic={nic}&passport={passport}&registrationNumber={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

你有什么主意吗?

0 个答案:

没有答案