美文网首页
url,path,query,headers

url,path,query,headers

作者: 余生筑 | 来源:发表于2017-11-18 15:51 被阅读129次

    Schema://host:port/path?query#hash

    =协议://主机名:端口号url
    =协议://域名/路径?参数集合#hash

    http://localhost:8080/Hello?i_need_money=true&how_much=1000
    

    等效于

    http://127.0.0.1:8080/Hello?i_need_money=true&how_much=1000
    

    由于端口号一般对应于协议名,So协议名可省略

    localhost:8080/Hello?i_need_money=true&how_much=1000
    

    其中

    • req.url为
      const url=req.url;
    req.url=/Hello?i_need_money=true&how_much=1000
    
    • path为
      const path=url.substr(0,url.indexOf('?'));
    /Hello
    
    • query为
      const querystring=url.substr(url.indexOf('?')+1,url.length);
      const query=qs.parse(querystring);
    {
     i_need_money: 'true', 
    how_much: '1000'
     }
    
    • headers(请求首部字段)为
    { host: '127.0.0.1:8080',
      connection: 'keep-alive',
      'content-length': '35',
      'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (K
    HTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36',
      'cache-control': 'no-cache',
      origin: 'chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop',
      'postman-token': 'd5ad522c-6cff-3c75-d724-a9e0e3a40743',
      'content-type': 'application/x-www-form-urlencoded',
      accept: '*/*',
      'accept-encoding': 'gzip, deflate, br',
      'accept-language': 'zh-CN,zh;q=0.9' }
    

    注意

    url,path,query负责告诉服务器资源的筛选条件
    headers内容规定request传递给response的数据格式(form-data,json,html)
    请求实体才真正放request传递给response的数据

    端口

    • 22=>ssh服务
    • 80=>http服务
    • 443=>https服务
    • 27017=>mongodb服务

    相关文章

      网友评论

          本文标题:url,path,query,headers

          本文链接:https://www.haomeiwen.com/subject/kxudvxtx.html