setrequestproperty参数_HttpURLConnection的addRequestProperty和setRequestProperty「建议收藏」

setrequestproperty参数_HttpURLConnection的addRequestProperty和setRequestProperty「建议收藏」一、当只有addRequestProperty的时候URLurl=newURL(“http://localhost:8080/net/listnets.jsp”);URLConnectionconnection=url.openConnection();connection.addRequestProperty(“name”,”asad”);connection.addReques…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

一、当只有addRequestProperty的时候

URL url = new URL(“http://localhost:8080/net/listnets.jsp”);

URLConnection connection = url.openConnection();

connection.addRequestProperty(“name”, “asad”);

connection.addRequestProperty(“name”, “komal”);

connection.addRequestProperty(“class”, “10th”);

connection.addRequestProperty(“Address”, “Delhi 17”);

Map map = connection.getRequestProperties();

Set set = map.entrySet();

Iterator iterator = set.iterator();

while (iterator.hasNext()) {

System.out.println(iterator.next());

}

输出结果:name=[komal, asad]

Address=[Delhi 17]

class=[10th]

二、当只有setRequestProperty的时候

URL url = new URL(“http://localhost:8080/net/listnets.jsp”);

URLConnection connection = url.openConnection();

connection.setRequestProperty(“name”, “komal”);

connection.setRequestProperty(“name”, “asad”);

connection.setRequestProperty(“class”, “10th”);

connection.setRequestProperty(“Address”, “Delhi 17”);

Map map = connection.getRequestProperties();

Set set = map.entrySet();

Iterator iterator = set.iterator();

while (iterator.hasNext()) {

System.out.println(iterator.next());

}

输出结果:

name=[asad]

Address=[Delhi 17]

class=[10th]

注意name的设置,会发生覆盖的作用。

三、当先set后add的时候

URL url = new URL(“http://localhost:8080/net/listnets.jsp”);

URLConnection connection = url.openConnection();

connection.setRequestProperty(“name”, “asad”);

connection.addRequestProperty(“name”, “komal”);

connection.addRequestProperty(“class”, “10th”);

connection.addRequestProperty(“Address”, “Delhi 17”);

Map map = connection.getRequestProperties();

Set set = map.entrySet();

Iterator iterator = set.iterator();

while (iterator.hasNext()) {

System.out.println(iterator.next());

}

输出结果

name=[komal, asad]

Address=[Delhi 17]

class=[10th]

四、当先add后set的时候

URL url = new URL(“http://localhost:8080/net/listnets.jsp”);

URLConnection connection = url.openConnection();

connection.addRequestProperty(“name”, “komal”);

connection.setRequestProperty(“name”, “asad”);

connection.addRequestProperty(“class”, “10th”);

connection.addRequestProperty(“Address”, “Delhi 17”);

Map map = connection.getRequestProperties();

Set set = map.entrySet();

Iterator iterator = set.iterator();

while (iterator.hasNext()) {

System.out.println(iterator.next());

}

name=[asad]

Address=[Delhi 17]

class=[10th]

五、结

setRequestProperty方法,如果key存在,则覆盖;不存在,直接添加。

addRequestProperty方法,不管key存在不存在,直接添加。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/195173.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Adobe Premiere Pro 2020(PR)系统兼容性报告(不支持的视频驱动程序)完美解决方案[通俗易懂]

    Adobe Premiere Pro 2020(PR)系统兼容性报告(不支持的视频驱动程序)完美解决方案[通俗易懂]背景近日,由于博主的笔记本电脑过于卡顿,升级了128GB的固态硬盘到512GB,重装系统后也需要重装生产力工具——Adobe系列全家桶。2019年10月,Adobe发布了最新的AdobePremierePro2020以及其他系列的最新版本全家桶应用,换了硬盘的博主自然要重装系统和重装AdobePremierePro2020等生产力工具。然而,在本次AdobePremiereP…

    2022年6月11日
    217
  • 虚拟机VMware安装苹果系统macOS,超级详细教程,附文件下载,真教程!!

    虚拟机VMware安装苹果系统macOS,超级详细教程,附文件下载,真教程!!1.准备工作1、虚拟机VMware®Workstation15Pro,小编使用的版本是15pro2、Unlocker或MK-Unlocker3、一个MacOS镜像2.资源下载…

    2022年9月25日
    0
  • Ubuntu安装dos2unix命令

    Ubuntu安装dos2unix命令Ubuntu系统打开Windows下生成的文本文件,会在每行的末尾出现’^M’原因就是Windows和Linux的回车符是不同的在Windows下回车符是\r\n回车换行在Linux下回车符是\n最简单、最常用的解决方法是使用dos2unix命令转换:dos2unixfilenameUbuntu下dos2unix和unix2dos命令在tofrodos包中安装:apt-g

    2022年5月31日
    38
  • linux定时执行shell脚本「建议收藏」

    linux定时执行shell脚本「建议收藏」写一个shell脚本,定时执行简单示例很多时候我们有希望服务器定时去运行一个脚本来触发一个操作,比如说定时去备份服务器数据、数据库数据等不适合人工经常做的一些操作这里简单说下 Shell俗称壳,类似于DOS下的command和后来的cmd.exe。它接收用户命令,然后调用相应的应用程序。作为命令语言,它交互式解释和执行用户输入的命令或者自动地解释和执行预先设定好的一连串的命令;作为程…

    2022年9月4日
    3
  • idea 2020 license server 激活码_通用破解码

    idea 2020 license server 激活码_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月17日
    942
  • 全局变量:global与$GLOBALS的区别和使用

    今天在写框架的时候想把SaeMySQL初始化之后作为全局变量使用。但是后来发现PHP中的全局变量和Java或者OC中的全局变量还是有较大区别的。下面记录一下php里面的global的使用相关注意事项。

    2021年12月27日
    40

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号