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!")
            };

 

posted @ 2021-08-20 14:54  Robot-Blog  阅读(598)  评论(0编辑  收藏  举报