62,614
社区成员
发帖
与我相关
我的任务
分享
InputStream inputStream = null;
BufferedReader in = null;
String path = null;
try {
path = ROOT_PATH
+ URLEncoder.encode(MESSAGE + smsContent + PHONE
+ phoneNumber + key, "utf-8");
URL url;
url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(15000);
conn.setReadTimeout(15000);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-type", "text/html");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
conn.setDoInput(true);
inputStream = conn.getInputStream();
String line;
in = new BufferedReader(new InputStreamReader(inputStream), 1024);
while ((line = in.readLine()) != null) {
if (line.length() > 0) {
Gson gson = new Gson();
Type type = new TypeToken<SMSResult>() {
}.getType();
smsResult = gson.fromJson(line, type);
}
}
} catch (Exception e) {
throw e;
} finally {
try {
if (null != in) {
in.close();
}
if (null != inputStream) {
inputStream.close();
}
} catch (Exception e) {
throw e;
}
}