From c51e85f52b04019a8fe2c5bce2beb3230bd2cc48 Mon Sep 17 00:00:00 2001 From: Mossimo Date: Mon, 3 May 2021 21:34:28 +0800 Subject: [PATCH] fix post --- .../Implementation/HttpProxyServiceImpl.cs | 21 ++++++++++++------- .../Implementation/HttpServiceImpl.cs | 6 +++++- src/ST/Services/IHttpService.cs | 4 ++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs b/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs index c5a484ed3..db343a96d 100644 --- a/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs @@ -66,11 +66,15 @@ namespace System.Application.Services.Implementation { //IHttpService.Instance.SendAsync(); var url = Web.HttpUtility.UrlDecode(e.HttpClient.Request.RequestUri.Query.Replace("?request=", "")); + var cookie = e.HttpClient.Request.Headers.GetFirstHeader("cookie-steamTool")?.Value?? e.HttpClient.Request.Headers.GetFirstHeader("Cookie")?.Value; + var headrs = new List() { new HttpHeader("Access-Control-Allow-Origin", e.HttpClient.Request.Headers.GetFirstHeader("Origin")?.Value ?? "*"), new HttpHeader("Access-Control-Allow-Headers", "*"), new HttpHeader("Access-Control-Allow-Methods", "*"), new HttpHeader("Access-Control-Allow-Credentials", "true")}; + //if (cookie != null) + // headrs.Add(new HttpHeader("Cookie", cookie)); switch (e.HttpClient.Request.Method.ToUpperInvariant()) { case "GET": - var body = await IHttpService.Instance.GetAsync(url); - e.Ok(body ?? "500", new List() { new HttpHeader("Access-Control-Allow-Origin", e.HttpClient.Request.Headers.GetFirstHeader("Origin")?.Value ?? "*"), new HttpHeader("Access-Control-Allow-Headers", "*") }); + var body =await IHttpService.Instance.GetAsync(url,cookie:cookie); + e.Ok(body??"500", headrs); return; case "POST": var requestStream = new StreamWriter(new MemoryStream()); @@ -82,8 +86,8 @@ namespace System.Application.Services.Implementation }; send.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(e.HttpClient.Request.ContentType); send.Content.Headers.ContentLength = e.HttpClient.Request.BodyString.Length; - var conext = await IHttpService.Instance.SendAsync(url, send, null, false, new CancellationToken()); - e.Ok(conext ?? "500", new List() { new HttpHeader("Access-Control-Allow-Origin", e.HttpClient.Request.Headers.GetFirstHeader("Origin")?.Value ?? "*"), new HttpHeader("Access-Control-Allow-Headers", "*") }); + var conext = await IHttpService.Instance.SendAsync(url, send,null,false,new CancellationToken()); + e.Ok(conext ?? "500", headrs); return; } //e.Ok(respone, new List() { new HttpHeader("Access-Control-Allow-Origin", e.HttpClient.Request.Headers.GetFirstHeader("Origin")?.Value ?? "*") }); @@ -100,9 +104,12 @@ namespace System.Application.Services.Implementation } if (e.HttpClient.Request.Host == "local.steampp.net") { - if (e.HttpClient.Request.Method.ToUpperInvariant() == "OPTIONS") - { - e.Ok("", new List() { new HttpHeader("Access-Control-Allow-Origin", e.HttpClient.Request.Headers.GetFirstHeader("Origin")?.Value ?? "*"), new HttpHeader("Access-Control-Allow-Headers", "*") }); + if (e.HttpClient.Request.Method.ToUpperInvariant() == "OPTIONS") { + e.Ok("", new List() { + new HttpHeader("Access-Control-Allow-Origin", e.HttpClient.Request.Headers.GetFirstHeader("Origin")?.Value ?? "*"), + new HttpHeader("Access-Control-Allow-Headers", "*"), + new HttpHeader("Access-Control-Allow-Methods", "*"), + new HttpHeader("Access-Control-Allow-Credentials", "true") }); return; } var type = e.HttpClient.Request.Headers.GetFirstHeader("requestType")?.Value; diff --git a/src/ST.Client/Services/Implementation/HttpServiceImpl.cs b/src/ST.Client/Services/Implementation/HttpServiceImpl.cs index d523ef6df..24104f699 100644 --- a/src/ST.Client/Services/Implementation/HttpServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/HttpServiceImpl.cs @@ -166,10 +166,14 @@ namespace System.Application.Services.Implementation public Task GetAsync( string requestUri, string accept, - CancellationToken cancellationToken) where T : notnull + CancellationToken cancellationToken, + string? cookie = null) where T : notnull { if (!IsHttpUrl(requestUri)) return Task.FromResult(default(T?)); var request = new HttpRequestMessage(HttpMethod.Get, requestUri); + if (cookie != null) { + request.Headers.Add("Cooike", cookie); + } request.Headers.Accept.ParseAdd(accept); request.Headers.UserAgent.ParseAdd(http_helper.UserAgent); return SendAsync(isCheckHttpUrl: true, requestUri, request, accept, true, cancellationToken); diff --git a/src/ST/Services/IHttpService.cs b/src/ST/Services/IHttpService.cs index b653d2ec4..8543bb55a 100644 --- a/src/ST/Services/IHttpService.cs +++ b/src/ST/Services/IHttpService.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -31,7 +31,7 @@ namespace System.Application.Services /// Task GetAsync(string requestUri, string accept = MediaTypeNames.JSON, - CancellationToken cancellationToken = default) where T : notnull; + CancellationToken cancellationToken = default,string? cookie = null) where T : notnull; /// /// (带本地缓存)通过 Get 请求 Image Stream