简体   繁体   中英

(java.net.SocketException) java.net.SocketException: Permission denied: connect

I am creating a sample application (java) which collection the information and send that information to the web service built in .net. Normally It is working fine. Both platform are communicating perfectly.

but after a sort of period I am getting (java.net.SocketException) java.net.SocketException: Permission denied: connect error.

I google it and found that JDK7 has issue. I just want to make sure it is only the issue of JDK7 or Can we handle it ?

I was using HTTPClient for client and HttpGet/HttpPost method for http request.

Now I changes the code by HttpClientBase for client and PostMethod/PutMethod for request. This has releaseConnection() method which is releasing the connection. and Now my code is working fine.

public void sendHttpPost() throws ClientProtocolException, IOException {
    HttpMethodBase httpPostRequest = new PostMethod(url + buildParams());


    try {
        // add headers
        Iterator it = headers.entrySet().iterator();
        while (it.hasNext()) {
            Entry header = (Entry) it.next();
            httpPostRequest.addRequestHeader((String) header.getKey(), (String) header.getValue());

        }
       ((PostMethod) httpPostRequest).setRequestEntity( new StringRequestEntity(new                                                    
    String(reqEntity), "text/plain", Constants.DEFAULT_ENCODING));
    try {
            respCode = client.executeMethod(httpPostRequest);
            response = httpPostRequest.getResponseBodyAsString();
            this.responsePhrase = httpPostRequest.getStatusText();

    }catch(Exception ex){
      System.out.println("ErrorS "+ex.toString());
        } finally {
            httpPostRequest.releaseConnection();
        }
    }catch(Exception ex){
      System.out.println("ErrorD "+ex.toString());
    }
        finally {

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM