大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
转载于:https://blog.csdn.net/yongwoozzang/article/details/83029128
HttpURLConnection x-www-form-urlencoded
public static String Post(String httpUrl, String data) {
PrintWriter out = null;
InputStream readStream = null;
String output = data;
String result = "";
try {
output = "value1=" + URLEncoder.encode(output, "UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
try {
URL postUrl = new URL(httpUrl);
HttpURLConnection conn = (HttpURLConnection) postUrl.openConnection();
conn.setConnectTimeout(5000);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Charset", "UTF-8");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");//关键代码 application/x-www-form-urlencoded
out = new PrintWriter(conn.getOutputStream());
out.print(output);
out.flush();
out.close();
if (conn.getResponseCode() != 200) {
throw new Exception("请求url失败");
}
readStream = conn.getInputStream();
result = ll.InputStreamToString(readStream);
return result;
} catch (Exception e) {
e.printStackTrace();
result = ll.InputStreamToString(readStream);
return result;
} finally {
if (out != null) {
out.close();
}
if (readStream != null) {
try {
readStream.close();
} catch (IOException e) {
return null;
}
}
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/185280.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...