1. 程式人生 > 其它 >NET WebApi 後端重定向指定連結

NET WebApi 後端重定向指定連結

重定向指定連結: usingSystem.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!")
            };