generated from root/miduo_server
疯体ios登陆问题处理
parent
b1cee1caa0
commit
bc738935c0
|
@ -42,7 +42,6 @@ public class HttpUtils {
|
|||
|
||||
public static String doPost2(String url, String json) throws IOException {
|
||||
PrintWriter out = null;
|
||||
BufferedReader in = null;
|
||||
String result = "";
|
||||
try {
|
||||
URL realUrl = new URL(url);
|
||||
|
@ -59,27 +58,23 @@ public class HttpUtils {
|
|||
out.print(json);
|
||||
// flush输出流的缓冲
|
||||
out.flush();
|
||||
// 定义BufferedReader输入流来读取URL的响应
|
||||
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
result += line;
|
||||
// 获取请求返回的数据流
|
||||
InputStream is = conn.getInputStream();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
// 封装输入流is,并指定字符集
|
||||
int i;
|
||||
while ((i = is.read()) != -1) {
|
||||
baos.write(i);
|
||||
}
|
||||
return baos.toString();
|
||||
} catch (Exception e) {
|
||||
System.out.println("发送 POST 请求出现异常!" + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 使用finally块来关闭输出流、输入流
|
||||
finally {
|
||||
try {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue