mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-27 12:46:53 +08:00
fix post
This commit is contained in:
@@ -66,11 +66,15 @@ namespace System.Application.Services.Implementation
|
||||
{
|
||||
//IHttpService.Instance.SendAsync<object>();
|
||||
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<HttpHeader>() { 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<string>(url);
|
||||
e.Ok(body ?? "500", new List<HttpHeader>() { 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<string>(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<string>(url, send, null, false, new CancellationToken());
|
||||
e.Ok(conext ?? "500", new List<HttpHeader>() { 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<string>(url, send,null,false,new CancellationToken());
|
||||
e.Ok(conext ?? "500", headrs);
|
||||
return;
|
||||
}
|
||||
//e.Ok(respone, new List<HttpHeader>() { 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<HttpHeader>() { 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<HttpHeader>() {
|
||||
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;
|
||||
|
||||
@@ -166,10 +166,14 @@ namespace System.Application.Services.Implementation
|
||||
public Task<T?> GetAsync<T>(
|
||||
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<T>(isCheckHttpUrl: true, requestUri, request, accept, true, cancellationToken);
|
||||
|
||||
@@ -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
|
||||
/// <returns></returns>
|
||||
Task<T?> GetAsync<T>(string requestUri,
|
||||
string accept = MediaTypeNames.JSON,
|
||||
CancellationToken cancellationToken = default) where T : notnull;
|
||||
CancellationToken cancellationToken = default,string? cookie = null) where T : notnull;
|
||||
|
||||
/// <summary>
|
||||
/// (带本地缓存)通过 Get 请求 Image Stream
|
||||
|
||||
Reference in New Issue
Block a user