- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
请告诉我一个,如何解决这个问题, 有时我收到 Filenotfound 异常,有时这段代码工作正常。
下面是我的代码,
public String sendSMS(String data, String url1) {
URL url;
String status = "Somthing wrong ";
try {
url = new URL(url1);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("User-Agent","Mozilla/5.0 ( compatible ) ");
conn.setRequestProperty("Accept","*/*");
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String s;
while ((s = rd.readLine()) != null) {
status = s;
}
rd.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
wr.close();
} catch (MalformedURLException e) {
status = "MalformedURLException Exception in sendSMS";
e.printStackTrace();
} catch (IOException e) {
status = "IO Exception in sendSMS";
e.printStackTrace();
}
return status;
}
最佳答案
像这样重写,让我知道你的进展......(注意关闭读写流,如果抛出异常,还要清理流)。
public String sendSMS(String data, String url1) {
URL url;
OutputStreamWriter wr = null;
BufferedReader rd = null;
String status = "Somthing wrong ";
try {
url = new URL(url1);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("User-Agent","Mozilla/5.0 ( compatible ) ");
conn.setRequestProperty("Accept","*/*");
wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
wr.close();
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String s;
while ((s = rd.readLine()) != null) {
status = s;
}
rd.close();
} catch (Exception e) {
if (wr != null) try { wr.close(); } catch (Exception x) {/*cleanup*/}
if (rd != null) try { rd.close(); } catch (Exception x) {/*cleanup*/}
e.printStackTrace();
}
return status;
}
关于Java,FileNotfound 异常,读取 conn.getInputStream() 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14582455/
所以我正在尝试实现类似 Imgur 的功能,非网站成员(member)的用户可以上传并继续编辑该上传内容(直到 cookie 被重置)。 当查看conn结构时,有3个地方出现了用户的cookie。 c
我已经用服务器和客户端完成了一个应用程序,以使用套接字 TCP 发送信息 问题是,如果函数 zfs.ReceiveSnapshot(在服务器端)没有返回错误(err == nil),conn.Writ
经常开发asp但对于细致的说法,真实不太清楚,这里简单的介绍下。 一般情况下 读取数据都是用rs.open sql,conn,1,1 修改数据:rs.open sql,conn,1,3 删除
后 iex -S mix phx.server 我想在 iex 终端做一些快速测试,但有些函数需要 struct %Plug.Conn{} 作为参数,例如我想得到表达式的结果: MyAppWeb.Ro
我正在尝试报告一些代码增强,但是,我不太确定这个项目叫什么。基本上,它不是执行 conn == null,而是执行 null == conn 以提高可读性。 之前: if (conn
这个问题在这里已经有了答案: Is this casting in golang? (1 个回答) What does "i.(string)" actually mean in golang syn
我的代码有点复杂,但简单来说,它有多个 go 例程,所有都调用不同的 TCP 服务器,并在流中出现可读消息时在 for 循环中读取输入。到目前为止,一切都很好。现在有另一个 go 例程来管理之前的一堆
我创建了一个 DBManager 类,如下所示 public class DBManager { public static String DRIVER = "oracle.jdbc.dr
在此处查看 Async/Await 示例: https://github.com/sidorares/node-mysql2/blob/master/documentation/Promise-Wra
在我的一个 Controller 中,我有以下代码(摘录): case HTTPoison.get("https://*****.zendesk.com/api/v2/users/search.jso
conn.execute('some string') 和 SQLAlchemy 中的 conn.execute(text('some string')) 有什么区别? 上面conn是通过conn =
我正在尝试使用btmgmt rust库读取连接的BLE设备的RSSI值,但总是得到127。。我确信该设备已连接,并已解决服务问题,下面是BluToothctl输出:。我尝试使用CLI呼叫btmgmt,
我正在使用MySQL Workbench 。如果我打开一个到 MySQL 的连接(在 Visual Basic 中),它将显示连接已打开。如果我关闭连接(在 MySQL Workbench 中),它会
我在 maven 项目中运行 selenium 测试。这个项目是 GWT Web 应用程序。在 pom.xml 中有 GWT 依赖项,hibernate 依赖项。我在测试包中创建了一个新类来运行 se
我尝试使用 HttpComponentsMessageSender 在 Spring WebServiceTemplate 中设置 ConnectionTimeout 和 ReadTimeout。但是
我刚刚将我的代码从 mysql 更改为 mysqli 并且最好是: 如何避免在每个查询或某些 mysqli 函数中使用 $conn? $conn = mysqli_connect("localhost
执行一条sql查询后,我想访问返回事件的id(主键),以便我可以在另一个sql中使用它。我尝试使用 result.insertId 访问它,但返回的事件对象似乎为 null。我什至控制台记录了 res
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界. 这篇CFSDN的博客文章Asp Conn.execute的参数与返回值总结由作者收集整理,如果你
我正在尝试使用GO与服务进行简单的UNIX套接字通信。为了测试,我创建了一个socket,如下所示: $ nc -vlU /tmp/sock Bound on /tmp/sock Listening
我很难对失败的测试进行故障排除,其中 conn.assigns 都是同一测试语句的一部分,但在测试的两行之间被清空。 我正在阅读“Programming Phoenix”,并重新编写代码以使其与 Ph
我是一名优秀的程序员,十分优秀!