更新时间:2023-12-04 14:49:40
请参阅 https://www.google.com/search?q=java%20sms [ ^ ]。
>
在您的代码中使用以下方法更改您的代码如下:
来自
In your code use the method below after changing your code as follow:
From
System.out.println(uc.getResponseMessage());
要
To
System.out.println(doHttpUrlConnectionAction(uc));
/**
* Returns the output from the given URL.
*
* I tried to hide exception-handling in this method, and just return a high
* level Exception from here.
* Modify this behavior as desired.
*
* @param connection
* @return
* @throws Exception
*/
private String doHttpUrlConnectionAction(HttpURLConnection connection)
throws Exception
{
BufferedReader reader = null;
StringBuilder stringBuilder;
try
{
connection.connect();
// read the output from the server
reader = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
stringBuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
stringBuilder.append(line + "\n");
}
return stringBuilder.toString();
}
catch (Exception e)
{
e.printStackTrace();
throw e;
}
finally
{
// close the reader; this can throw an exception too, so
// wrap it in another try/catch block.
if (reader != null)
{
try
{
reader.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
}