zoukankan      html  css  js  c++  java
  • webapi Action中跳转到指定内容

    最近项目里面有用到webapi接口作为回调页面,然后由页面展示回调内容

            [HttpGet]
            [ActionName("ScanQRCodeCallBack")]
            public System.Net.Http.HttpResponseMessage ScanQRCodeCallBack(string ticket)
            {
    
                //读取所有cookie
                StringBuilder sb = new StringBuilder();
                foreach (var item in this.Request.Headers)
                {
                    sb.Append(($"key:{item.Key} value:{item.Value.ToArray()[0]}"));
                    sb.Append("</br>");
                }
                sb.Append("key:ticket value:" + ticket);
                string cookieStr = sb.ToString();
    
                Console.WriteLine(cookieStr);
                //重定向到指定页面
                var requestUri = this.Request.RequestUri;
                string newUrl = $"{requestUri.Scheme}://{requestUri.Authority}/webui/index.html{requestUri.Query}";
                //直接跳转
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.Moved);
                resp.Headers.Location = new Uri(newUrl);
                //resp.Headers.Add("Set-Cookie", cookieStr);
                return resp;
    
    
    
                //测试 直接返回cookie页面
                var cookie = new System.Net.Http.StringContent(sb.ToString());
                cookie.Headers.ContentType.MediaType = "text/html";
                System.Net.Http.HttpResponseMessage cookieMessage = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
                cookieMessage.Content = cookie;
                return cookieMessage;
    
    
                //测试 返回指定字符串
                string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "webui", "index.html");
                string readHtml = System.IO.File.ReadAllText(path, Encoding.UTF8);
                var rValue = new System.Net.Http.StringContent(readHtml);
                //var rValue = new System.Net.Http.StringContent($"<a href='http://www.baidu.com'>{ticket}</a>", Encoding.UTF8, "text/html");
                rValue.Headers.ContentType.MediaType = "text/html";
                System.Net.Http.HttpResponseMessage msg = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
                msg.Headers.Add("Set-Cookie", "aa=xxxx");
                msg.Content = rValue;
                return msg;
            }
  • 相关阅读:
    zookeeper集群搭建
    kafka集群安装与配置
    Spring Task 定时任务配置与使用
    6.Spark SQL 及其DataFrame的基本操作
    10 期末大作业
    09 spark连接mysql数据库
    08 学生课程分数的Spark SQL分析
    从RDD创建DataFrame 07
    RDD 编程5
    05 RDD练习:词频统计
  • 原文地址:https://www.cnblogs.com/LittleJin/p/14447340.html
Copyright © 2011-2022 走看看