该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
下面上代码
public static String executeHttpPost(String strURL,String pamars) {
String result = null;
URL url = null;
HttpURLConnection connection = null;
InputStreamReader in = null;
OutputStream dop = null;
try {
url = new URL(strURL);
connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(15*1000);
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
//设置请求的头
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Charset", "utf-8");
dop = connection.getOutputStream();
dop.write(pamars.toString().getBytes("UTF-8"));
connection.connect();
dop.flush();
in = new InputStreamReader(connection.getInputStream());
BufferedReader bufferedReader = new BufferedReader(in);
StringBuffer strBuffer = new StringBuffer();
String line = null;
while ((line = bufferedReader.readLine()) != null) {
strBuffer.append(line);
}
bufferedReader.close();
connection.disconnect();
result = strBuffer.toString();
return result;
} catch (Exception e) {
try {
int code = connection.getResponseCode();
String a = "";
} catch (IOException e1) {
e1.printStackTrace();
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(baos));
String exception = baos.toString();
String a = exception;
return a;
} finally {
if (connection != null) {
connection.disconnect();
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (dop!=null){
try {
dop.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
url和pamars都没有问题
求大神解决啊