post跨域get不跨域_request获取请求的域名

post跨域get不跨域_request获取请求的域名转载博客一、当只有addRequestProperty的时候[html]viewplaincopyprint?URL url = new URL(“http://localhost:8080/net/listnets.jsp”);              URLConnection connection = url.openConnection();              conne

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

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

转载博客

一、当只有addRequestProperty的时候

  1. URL url = new URL(“http://localhost:8080/net/listnets.jsp”);  
  2.             URLConnection connection = url.openConnection();  
  3.             connection.addRequestProperty(“name”, “asad”);  
  4.             connection.addRequestProperty(“name”, “komal”);  
  5.             connection.addRequestProperty(“class”, “10th”);  
  6.             connection.addRequestProperty(“Address”, “Delhi 17”);  
  7.   
  8.             Map map = connection.getRequestProperties();  
  9.             Set set = map.entrySet();  
  10.   
  11.             Iterator iterator = set.iterator();  
  12.             while (iterator.hasNext()) {  
  13.                 System.out.println(iterator.next());  
  14.             }  
 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());
                }
  1. 输出结果:name=[komal, asad]  
  2. Address=[Delhi 17]  
  3. class=[10th]  
输出结果:name=[komal, asad]
Address=[Delhi 17]
class=[10th]

二、当只有setRequestProperty的时候

  1. URL url = new URL(“http://localhost:8080/net/listnets.jsp”);  
  2. URLConnection connection = url.openConnection();  
  3. connection.setRequestProperty(“name”, “komal”);  
  4. connection.setRequestProperty(“name”, “asad”);  
  5. connection.setRequestProperty(“class”, “10th”);  
  6. connection.setRequestProperty(“Address”, “Delhi 17”);  
  7.   
  8. Map map = connection.getRequestProperties();  
  9. Set set = map.entrySet();  
  10.   
  11. Iterator iterator = set.iterator();  
  12. while (iterator.hasNext()) {  
  13.     System.out.println(iterator.next());  
  14. }  
             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());
                }
  1. 输出结果:  
输出结果:
  1. name=[asad]  
  2. Address=[Delhi 17]  
  3. class=[10th]  
name=[asad]
Address=[Delhi 17]
class=[10th]
  1. 注意name的设置,会发生覆盖的作用。  
注意name的设置,会发生覆盖的作用。

三、当先set后add的时候

 
 
  1. URL url = new URL(“http://localhost:8080/net/listnets.jsp”);  
  2.         URLConnection connection = url.openConnection();  
  3.         connection.setRequestProperty(“name”, “asad”);  
  4.         connection.addRequestProperty(“name”, “komal”);  
  5.         connection.addRequestProperty(“class”, “10th”);  
  6.         connection.addRequestProperty(“Address”, “Delhi 17”);  
  7.   
  8.         Map map = connection.getRequestProperties();  
  9.         Set set = map.entrySet();  
  10.   
  11.         Iterator iterator = set.iterator();  
  12.         while (iterator.hasNext()) {  
  13.             System.out.println(iterator.next());  
  14.         }  
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());
        }
  1. 输出结果  
输出结果
  1. name=[komal, asad]  
  2. Address=[Delhi 17]  
  3. class=[10th]  
name=[komal, asad]
Address=[Delhi 17]
class=[10th]
  1.    
 
  1.    
 

四、当先add后set的时候

  1. URL url = new URL(“http://localhost:8080/net/listnets.jsp”);  
  2.         URLConnection connection = url.openConnection();  
  3.         connection.addRequestProperty(“name”, “komal”);  
  4.         connection.setRequestProperty(“name”, “asad”);  
  5.         connection.addRequestProperty(“class”, “10th”);  
  6.         connection.addRequestProperty(“Address”, “Delhi 17”);  
  7.   
  8.         Map map = connection.getRequestProperties();  
  9.         Set set = map.entrySet();  
  10.   
  11.         Iterator iterator = set.iterator();  
  12.         while (iterator.hasNext()) {  
  13.             System.out.println(iterator.next());  
  14.         }  
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());
        }

 

  1. name=[asad]  
  2. Address=[Delhi 17]  
  3. class=[10th]  
name=[asad]
Address=[Delhi 17]
class=[10th]

五、结

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

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

 

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

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

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


相关推荐

  • netstat命令详解

    netstat命令详解简介netstat命令用于显示各种网络相关信息,如网络连接,路由表,接口状态(InterfaceStatistics),masquerade连接,多播成员(MulticastMember

    2022年7月3日
    24
  • Oracle数据库备份与恢复方案

    Oracle数据库备份与恢复方案任何数据库在长期使用过程中,都会存在安全隐患。对于数据库管理员来说不能仅寄希望于计算机操作系统的安全运行,而是要建立一整套的数据库备份与恢复机制。当任何人为的或是自然的灾难一旦出现,而导致数据库崩溃、物理介质损坏等,就可以及时恢复系统中重要的数据,不影响整个单位业务的运作。然而如果没有可靠的备份数据和恢复机制,就会带来系统瘫痪、工作停滞、经济损失等等不堪设想的后果。本文以ORACLE数据库为例,结

    2022年7月14日
    33
  • 卡尔曼滤波(KF)与扩展卡尔曼滤波(EKF)的一种理解思路及相应推导(1)

    卡尔曼滤波(KF)与扩展卡尔曼滤波(EKF)的一种理解思路及相应推导(1)前言:从上个世纪卡尔曼滤波理论被提出,卡尔曼滤波在控制论与信息论的连接上做出了卓越的贡献。为了得出准确的下一时刻状态真值,我们常常使用卡尔曼滤波、扩展卡尔曼滤波、无迹卡尔曼滤波、粒子滤波等等方法,这些方法在姿态解算、轨迹规划等方面有着很多用途。卡尔曼滤波的本质是参数化的贝叶斯模型,通过对下一时刻系统的初步状态估计(即状态的先验估计)以及测量得出的反馈相结合,最终得到下一时刻较为准确的的状态估计

    2022年6月28日
    48
  • quota的使用方法

    from:http://man.chinaunix.net/linux/how/Quota.html   序言:这份文件的版权由AlbertM.C.Tam(bertie@scn.org)所保留。同意这份文件的使用、复制,因此非商业性的散布是允许的,但是所有的拷贝以及/或是没有修改直接援用的文件上须有作者与编者的名字及这份注意事项。这份文件是因为希望能有所帮助

    2022年4月8日
    49
  • wondows中的cmd中切换盘符和目录的命令「建议收藏」

    wondows中的cmd中切换盘符和目录的命令「建议收藏」一般介绍DOS命令,切换工作目录都是用CD命令,但是我在win7下的DOS中使用CDD:\却一直无法转到D盘。后来在网上查找,发现切换盘符直接输入盘符和冒号,如D: 回车便可进入D盘的根目录。切换工作盘之后,再使用CD命令切换工作目录。****************************************************************************

    2022年10月3日
    5
  • “儿子,千万别帮老婆做家务!”爸爸写的这封信火了

    文 | 十二朵女王 · 主播 | 维维 儿子,明天就是你的婚礼了。 我必须提醒你,一旦结了婚,你就有了自己的新家,我和你妈不用你操心,你只用竭尽全力照顾好你自己…

    2021年6月21日
    81

发表回复

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

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