在java 设置
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Charset", "UTF-8");
// 设置文件类型:
conn.setRequestProperty("Content-Type","application/json; charset=UTF-8");
在 ajax 中的请求设置类型
两者的区别就是 中间的横杠 -
本文对比了Java中使用URL和URLConnection发送HTTP请求与Ajax中设置请求的不同之处,包括如何设置请求属性如连接方式、字符集及内容类型。
11万+

被折叠的 条评论
为什么被折叠?



