java http接口post提交方法

public String send(String phone, String content, String sendtime) {

String urlStr = "http:// 113.106.90.218/SIAdmin/submit.do";

String id = "账号";//账号

String password = "密码";//密码

String Str = "user=" + id + "&pwd=" + password + "&phone=" + phone

"&content=" + content + "&sendtime=" + sendtime;

String res = "";//返回值

try {

URL url = new URL(urlStr);

URLConnection connection = url.openConnection();

connection.setDoOutput(true);

OutputStreamWriter outs = new OutputStreamWriter(connection

.getOutputStream(), "UTF-8");

outs.write(Str);

outs.flush();

outs.close();

BufferedReader reader = new BufferedReader(new InputStreamReader(connection

.getInputStream()));

res = reader.readLine();//获取返回值

reader.close();

catch (Exception ex2) {

System.out.println(" exe IOException:" + ex2.toString());

return "FAILURE";

}

return res;

}

<!--EndFragment-->

猜你喜欢

转载自zdk8105.iteye.com/blog/1488190