(java.net.SocketException)java.net.SocketException:权限被拒绝:连接

时间:2013-11-05 13:04:25

标签: java asp.net web-services sockets

我正在创建一个示例应用程序(java),它收集信息并将该信息发送到.net内置的Web服务。通常它工作正常。两个平台都完美地沟通。

但经过一段时间后我得到(java.net.SocketException)java.net.SocketException:权限被拒绝:连接错误。

我谷歌并发现JDK7有问题。我只是想确保它只是JDK7的问题或我们可以处理吗?

1 个答案:

答案 0 :(得分:1)

我正在使用HTTPClient用于客户端,而HttpGet / HttpPost方法用于http请求。

现在我通过HttpClientBase为客户端和PostMethod / PutMethod更改代码以获取请求。这有释放连接的releaseConnection()方法。现在我的代码工作正常。

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 {

    }
}