gpt4 book ai didi

java - 如何从struts中的java Action 调用url?

转载 作者:行者123 更新时间:2023-12-01 15:59:36 25 4
gpt4 key购买 nike

我正在尝试通过如下网址发送短信

public  void sendsms() throws IOException 
{
URL sms = new URL("http://india.timessms.com/http- api/receiverall.asp?username=way2sijo&password=*******i&sender=Demo&cdmasender=9930065297&to=919930065297&message=Hello");
BufferedReader in = new BufferedReader(
new InputStreamReader(sms.openStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);

in.close();
}

但是在运行这个程序时显示以下异常

in thread "main" java.net.SocketException: Network is unreachable: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)

我该如何解决这个问题......提前致谢......

最佳答案

最好查看 apache http 客户端库并使用它发出 get 请求。

关于java - 如何从struts中的java Action 调用url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4285724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com