java.net.SocketException: Permission denied: connect

记录下这个错误,在调用阿里云的接口时一直报这个错误

java.net.SocketException: Permission denied: connect_第1张图片

java.net.SocketException: Permission denied: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:127)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
at com.aliyun.api.gateway.demo.util.HttpUtils.doPost(HttpUtils.java:127)
at com.alibaba.ocr.demo.APPCodeDemo.main(APPCodeDemo.java:108)

Disconnected from the target VM, address: '127.0.0.1:64387', transport: 'socket'


后查找非常多的文档都说是JDK 1.7和Windows 7中的已知错误有关。问题可能是应用程序不完全支持IPv6,也不是网络/防火墙不完全支持IPv6。解决方法是-Djava.net.preferIPv4Stack=true在Java或Maven命令行参数中设置。

至于设置,因为我使用的是idea,所以设置如下


进入修改界面,设置 vm options 中参数如下

-Djava.net.preferIPv4Stack=true

java.net.SocketException: Permission denied: connect_第2张图片

设置完成之后启动,可以正常调用。


你可能感兴趣的:(HttpClient,Exception)