XFire平台下的连接超时设置

    public Client loadClient() throws MalformedURLException, Exception{
        Client client = new Client(new URL(url));
        client.setTimeout(20000);
        HttpClientParams params = new HttpClientParams();
        // 避免'Expect: 100-continue' handshake
        params.setParameter(HttpClientParams.USE_EXPECT_CONTINUE,Boolean.FALSE);
        //设置ws连接超时时间
        params.setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, 20000l);
        client.setProperty(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS,params);
        return client;
    }

 

以上的做法在实际项目中发现行不通,现修改为:

        URL _url = new URL(url);
        HttpURLConnection httpConnection = (HttpURLConnection)_url.openConnection();
        httpConnection.setReadTimeout(20000);//设置http连接的读超时,单位是毫秒

        httpConnection.connect();
        Client _client = new Client(httpConnection.getInputStream(), null);
        _client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, String.valueOf( 20000 ));//设置发送的超时限制,单位是毫秒;
        _client.setProperty(CommonsHttpMessageSender.DISABLE_KEEP_ALIVE, "true");
        _client.setProperty(CommonsHttpMessageSender.DISABLE_EXPECT_CONTINUE, "true");

实践检验,可行!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
设置WebService调用的超时时间,可以按照以下步骤进行操作。 首先,需要在WebService的客户端代理程序中设置请求超时时间。可以在GetWebRequest方法中设置超时时间,单位是毫秒。例如,可以将超时时间设置为30秒(30 * 1000毫秒)\[2\]。 其次,需要在调用WebService接口的代码中设置超时时间。可以在调用方法之前设置超时时间。例如,可以使用try-catch块来捕获异常,并在catch块中设置超时时间。可以使用setTimeOut方法来设置超时时间,单位是毫秒。例如,可以将超时时间设置为30秒(30 * 1000毫秒)\[3\]。 通过以上步骤,就可以设置WebService调用的超时时间,以确保在超时时间内获取到响应。 #### 引用[.reference_title] - *1* *2* [调用webservice 设置超时时间](https://blog.csdn.net/qq_44884269/article/details/89321377)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Xfire生成WebService客户端代码 调用 并设置超时时间](https://blog.csdn.net/wzq0926/article/details/125758476)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值