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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 即时通讯源代码,im源码功能全套[通俗易懂]

    即时通讯源代码,im源码功能全套[通俗易懂]即时通讯源代码,im源码,im源代码即时通讯全套源码语言:C/C++语言编写,VC++开发平台产品包含完善的即时通讯系统,是一套集即时通讯和视频会议为一体的企业级办公协同交流产品,可以广泛应用于政府、企业、教育机构和公司等客户端:大致功能(具体以产品演示为准):在线文字聊天离线留言历史消息记录查询 公告消息提醒语音聊天 视频聊天群发留言 输入状态感知个…

    2022年5月14日
    247
  • linux load average,Linux Load Average详解

    linux load average,Linux Load Average详解定义在Linux,以及其他类Unix的系统中,常用该系统正在进行的运算工作来衡量该系统的系统负荷(SystemLoad)。一个完全空闲的系统,它的负荷(SystemLoad)标记为0;每一个正在运行或者正在等待CPU资源的进程,会导致平均负荷(SystemLoad)加1。所以,如果一个系统的负荷是4,就是说有4个进程正在使用,或者正在等待CPU资源。因为系统负荷(SystemLoad)是…

    2022年7月17日
    17
  • pycharm怎么安装requests模块_python3安装模块

    pycharm怎么安装requests模块_python3安装模块问题引入:今天在学习Python网络请求的时候,导入requests模块时一直报红色波浪线,如图:反复折腾,一直以为自己没有安装requests模块,反复安装反复卸载:安装方法:首先cd进入C:\Python27\Scripts 执行pipinstallrequests命令可以自动安装卸载方法:首先cd进入C:\Python27\Scripts 执行pipuninstallr…

    2022年8月26日
    9
  • 随机梯度下降算法原理 知乎_梯度下降算法的正确步骤

    随机梯度下降算法原理 知乎_梯度下降算法的正确步骤目录1.算法目标2.算法描述3.算法推导4.注意1.算法目标逐渐逼近损失函数loss的极小值,简单抽象为求函数的极小值。2.算法描述每次取一个增量,使得,每次向函数值更小的地方前进一小步,多次迭代就能做到逐渐逼近函数的极小值。3.算法推导展开得到公式。其中H为海森矩阵,暂且不考虑。为使成立,只需要保证。即,当时,,如此即可保证每次更新在逐渐逼近函数的极小值。其中为学习率是一个较小的正数。每次更新时做操作,求得的最小值。4.注意上..

    2025年9月7日
    5
  • 递归和迭代的差别

    递归和迭代的差别

    2021年11月30日
    41
  • IIS 安装失败之解决方案[通俗易懂]

    IIS 安装失败之解决方案[通俗易懂]首先删除IIS后,再开始下面的操作:1.运行:regsvr32%windir%/system32/vbscript.dll(其实这一步也可以省,确保万一,还是执行吧)2.运行:msdtc-resetlog3.重新安装IIS…

    2022年6月4日
    36

发表回复

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

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