zoukankan      html  css  js  c++  java
  • res对象json,redirect

     1.res.json()

    var express=require('express');
    var app=express();
    
    app.get('/',function(req,res){
        //返回json,
        res.json({name:'jim',age:'100'});
    })
    
    app.listen(9090,function(){
        console.log('http://localhost:9090');
    })

    res.json()将参数转化为json对象,请求方式和res.send差不多

    2.res.redirect([status,] path)

    重定向到从指定的URL到的另一个URL ,具有指定的statusHTTP状态代码对应的正整数如果未指定,则status默认为“302”找到“。

    res.redirect('/foo/bar');
    res.redirect('http://example.com');
    res.redirect(301, 'http://example.com');
    res.redirect('../login');

    重定向可以是用于重定向到其他站点的完全限定URL:

    res.redirect('http://google.com');

    重定向可以相对于主机名的根目录。例如,如果应用程序已启用http://example.com/admin/post/new,则以下内容将重定向到URL http://example.com/admin

    res.redirect('/admin');

    重定向可以相对于当前URL。例如,从http://example.com/blog/admin/(注意尾部斜杠),以下将重定向到URL http://example.com/blog/admin/post/new

    res.redirect('post/new');

    重定向到post/newhttp://example.com/blog/admin(没有尾随斜线),会重定向到http://example.com/blog/post/new

    如果您发现上述行为令人困惑,请将路径段视为目录(带有斜杠)和文件,它将开始有意义。

    路径相对重定向也是可能的。如果您在 http://example.com/admin/post/new,以下将重定向到 http://example.com/admin/post

    res.redirect('..');

    一个back重定向请求重定向回引荐,默认为/引荐丢失时。

    res.redirect('back');
     
  • 相关阅读:
    递归求解的两道小练习
    unittest的前置后置,pytest的fixture和共享机制conftest.py
    pytest + allure
    Jmeter 录制 https协议是出现“您访问的不是安全链接”提示时
    Jmeter
    如何不做登录请求而获取cookie到Jmeter里
    Fiddler抓包后转成jmeter脚本
    Jmeter- 笔记12
    Jmeter- 笔记11
    Jmeter- 笔记10
  • 原文地址:https://www.cnblogs.com/ellen-mylife/p/11072085.html
Copyright © 2011-2022 走看看