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


相关推荐

  • mysql45讲pdf_讲政策读后感

    mysql45讲pdf_讲政策读后感此文为极客时间:MySQL实战45讲的2、15节日志相关部分和网上一些相关文章的内容的总结一、redolog1.概述redolog又叫重做日志,提供的是数据丢失后的前滚操作。redol

    2022年8月16日
    5
  • git 提交代码常用命令

    git 提交代码常用命令 一、master分支代码提交过程 gitlog 查看git合入的记录    gitpull从服务器重新拉代码,将本地代码更新为服务器上的最新代码 gitstatus查看本地代码状态,是否有待提交的代码  git add.  将本地代码全部提交  gitcommit-m"合入新的PUCCH和小区功率代码"   为本次提交添加注释 …

    2022年6月26日
    43
  • h2数据库使用(h2数据库生成的文件)

    h2数据库进入shelljava-cp../lib/h2-1.4.200.jarorg.h2.tools.ShellWelcometoH2Shell1.4.200(2019-10-14)ExitwithCtrl+C[Enter]jdbc:h2:~/testURLjdbc:h2:/usr/local/db/xxx-xxx[Enter]org.h2.DriverDriver[Enter]UserxxxxxxPasswo

    2022年4月12日
    44
  • springboot实现拦截器_springmvc自定义拦截器

    springboot实现拦截器_springmvc自定义拦截器集成拦截器登录验证为例添加拦截器public class LoginInterceptor implements HandlerInterceptor { private Logger log = LoggerFactory.getLogger(getClass()); //Controller逻辑执行之前 @Override public boolean preHandle(HttpServletRequest request, HttpServletRe

    2022年8月8日
    8
  • winform使用SplitContainer控件[通俗易懂]

    winform使用SplitContainer控件[通俗易懂]在Windows资源管理器中,当把鼠标指针移动到TreeView控件和ListView控件之间时,可以左右拖动鼠标调整TreeView控件和ListView控件在主窗口中的大小比例,以适应不同显示内容的需要。我们可以使用SplitContainer控件实现这种功能。  可

    2022年7月18日
    96
  • 电力系统分析matlab仿真_电力系统稳定性分析

    电力系统分析matlab仿真_电力系统稳定性分析基于Wirtinger不等式的时滞电力系统稳定性判定方法【专利摘要】本发明公开了一种基于Wirtinger不等式的时滞电力系统稳定性判定方法,用于分析电力系统所能承受的最大时滞稳定裕度。该方法的具体步骤如下:首先,建立考虑时滞影响的电力系统模型。然后,针对所建模型构建Lyapunov泛函,在泛函的求导过程中通过采用Wirtinger不等式进行放缩,以减少判据的保守性。最后将所得判据用一组线性矩阵不…

    2022年10月1日
    5

发表回复

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

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