NET WebApi 后端重定向指定链接

重定向指定链接: using System.Net.Http;using System.Net.Http.Headers;

                var location = $"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Authority}/index.html";
                _nLogUtil.Info($"location:{location}\trspData:{rsp.Data.ToJson()}");

                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.Moved);
                resp.Headers.Location = new Uri(location);return resp;

添加Cookie:using System.Net.Http.Headers;

                if (!rsp.Data.CookieList.IsNullOrEmpty())
                {
                    var cookieList = rsp.Data.CookieList.Select(x => new CookieHeaderValue(x.Item1, x.Item2));
                    _nLogUtil.Info($"cookieList: {cookieList.ToJson()}");
                    resp.Headers.AddCookies(cookieList);
                }

返回文本信息

            return new HttpResponseMessage
            {
                Content = new StringContent("Hello World!")
            };

 

上一篇:怎么下载m3u8格式视频?Python爬取A站m3u8格式视频案例讲解


下一篇:python常用数据转换