C# 请求正文已加密

C# 请求正文已加密,c#,json,asp.net-core-mvc,C#,Json,Asp.net Core Mvc,我正在尝试使用以下代码从移动应用程序接收JSON请求到我的站点: [HttpPost] [Route("{platform:minlength(2)}/{leagueID:int}/leagueteams")] public IActionResult ExportLeagueTeams([FromRoute] string platform, [FromRoute] int leagueID) { if (!string.IsNullOrEmpty(this.logFile))

我正在尝试使用以下代码从移动应用程序接收JSON请求到我的站点:

[HttpPost]
[Route("{platform:minlength(2)}/{leagueID:int}/leagueteams")]
public IActionResult ExportLeagueTeams([FromRoute] string platform, 
[FromRoute] int leagueID)
{

    if (!string.IsNullOrEmpty(this.logFile))
    {
        try
        {
            using (StreamWriter writer = new StreamWriter(this.logFile, true))
            {
                writer.WriteLineAsync("***").Wait();
                writer.WriteLineAsync("Testing this log").Wait();
                writer.WriteLineAsync("Platform: " + platform).Wait();
                writer.WriteLineAsync("LeagueID: " + leagueID).Wait();
                writer.WriteLineAsync("HEADERS:").Wait();

                // Get the headers
                foreach (var header in Request.Headers)
                {
                    writer.WriteLineAsync(header.Key + ": " + header.Value).Wait();
                }

                writer.WriteLineAsync("BODY (raw):").Wait();

                // get the Body of the request
                using (var reader = new StreamReader(Request.Body))
                {
                    var body = reader.ReadToEnd();
                    writer.WriteLineAsync(body).Wait();
                }
            }

            return Ok();
        }
        catch (Exception e)
        {
            return BadRequest();
        }
    }
    else
    {
        return BadRequest();
    }
}
这将从我尝试使用的移动应用程序中获取请求,但是,请求正文看起来。。。。古怪的它肯定是加密的或二进制的。我无法从我的日志中复制和粘贴,因为主体仅被复制和粘贴为

正文: �

请求标头如下所示:

HEADERS:
Connection: Keep-Alive
Content-Type: application/json
Content-Encoding: gzip
Accept: application/json
Host: mywebsite.azurewebsites.net
Max-Forwards: 10
User-Agent: ProtoHttp 1.3/DS 15.1.2.2.0 (Android)
Content-Length: 1811
X-WAWS-Unencoded-URL: /api/Madden/ps4/6909313/leagueteams
CLIENT-IP: 73.13.26.24:47529
X-ARR-LOG-ID: 425fb24e-aa9f-4422-9dd2-b3b407240453
DISGUISED-HOST: mywebsite.azurewebsites.net
X-SITE-DEPLOYMENT-ID: mysebsite
WAS-DEFAULT-HOSTNAME: mywebsite.azurewebsites.net
X-Original-URL: /api/Madden/ps4/6909313/leagueteams
X-Forwarded-For: 73.13.26.24:47529
X-ARR-SSL: 2048|256|C=US, S=Washington, L=Redmond, O=Microsoft Corporation, OU=Microsoft IT, CN=Microsoft IT TLS CA 4|CN=*.azurewebsites.net
X-Forwarded-Proto: https
MS-ASPNETCORE-TOKEN: 8c86c695-eec2-4328-a7ed-b2c2f10b9603
X-Original-For: 127.0.0.1:56457
X-Original-Proto: http

如何解码/解密请求正文?

我能做到!文件被压缩了

使用,我能够将以下内容添加到Startup.cs代码中

配置服务代码


非常感谢@IanKemp向正确的方向推进

您有权访问发送请求的代码吗?也许他们使用了另一种字符编码。你能尝试使用Encoding.ASCII.getStrings吗?你确定数据不仅仅是压缩的,而且你使用的与请求相关的代码/类只是无法/拒绝解压缩吗?请注意,请求头明确声明内容是GZip压缩的。当然,我的评论只是猜测。我希望与请求相关的类能够透明地处理解压缩,但我对ASP.NET没有太多经验。快速检查数据是否仍在进行gzip压缩-这不是建议如何改进/更改生产代码!!!-,您可以使用并查看它是否可以成功解压缩数据。1/22/2如果数据不再是GZip压缩的,即GZipStream没有帮助,我建议将服务器获取的数据转储到某个临时文件中,然后使用某个十六进制编辑器对其进行检查,试图确定该数据实际上可能是什么。。。
/// <summary>
/// This method gets called by the runtime. Use this method to add services to the container.
/// </summary>
/// <param name="services">Services to include</param>
public void ConfigureServices(IServiceCollection services)
{
    services.Configure<CookiePolicyOptions>(options =>
    {
        // This lambda determines whether user consent for non-essential cookies is needed for a given request.
        options.CheckConsentNeeded = context => true;
        options.MinimumSameSitePolicy = SameSiteMode.None;
    });

    // Add Decompression options
    var decompressOptions = new RequestDecompressionOptions();
    decompressOptions.UseDefaults();
    decompressOptions.AddProvider<GzipDecompressionProvider>();
    decompressOptions.SkipUnsupportedEncodings = false;
    services.AddRequestDecompression(decompressOptions);

    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

    var connection = Configuration.GetConnectionString("MySiteUsers");
    var mailingListConnection = Configuration.GetConnectionString("MailingList");
    services.AddDbContext<MySiteContext>(options => options.UseSqlServer(connection));
    services.AddDbContext<MySiteMailingListContext>(options => options.UseSqlServer(mailingListConnection));
}
/// <summary>
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Home/Error");
        app.UseHsts();
    }

    // This is where you use the Request Decompression
    app.UseRequestDecompression();
    app.UseHttpsRedirection();
    app.UseStaticFiles();
    app.UseCookiePolicy();

    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "areas",
            template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
        );
    });
}