All Products
Document Center

:"Connection to XXXX refused" Error in Using OSS Java SDK Times

Last Updated:May 19, 2022

Problem description

When you use the OSS Java SDK, an error message similar to the following is reported.

Connection to refused
[RequestId]: Unknown
        at com.aliyun.oss.common.utils.ExceptionFactory.createNetworkException(
        at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(
        at com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl(
        at com.aliyun.oss.common.comm.ServiceClient.sendRequest(
        at com.aliyun.oss.internal.OSSOperation.send(
        at com.aliyun.oss.internal.OSSObjectOperation.putObject(
        at com.aliyun.oss.OSSClient.putObject(
        at osscs1.OSSPutObjectSample.uploadFile(
      at osscs1.OSSPutObjectSample.main(


  • The client and OSS are not in the internal network of the same region, so you cannot use the endpoints of the internal network. You need to use the endpoints of the public network.
  • Although the client and OSS are in the same area, the client may have some special restrictions, such as the port is not open.


We recommend that you use the ping command on the client to test the endpoint address of the Internet and the telnet command to test whether port 80/443 is normal. If the test is normal, configure the OSS Java SDK as follows.

OSSClient client = new OSSClient(OSS_ENDPOINT,ACCESS_ID, ACCESS_KEY); of private static final String OSS_ENDPOINT = ""; 

Note: This topic uses the address in the Hangzhou region as an example. For other regions, modify the endpoint based on the details of the domain name and data center. For more information, see Access domain name and data center.

Applicable scope

  • Object Storage Service (OSS)