小编Mar*_*cus的帖子

分段表单文件上传 - 上传的文件有时在文件末尾有额外的换行符

我有一个非常疯狂的问题,我希望有人能给我一些如何解决它的建议。

在客户端,我使用 C# 将多部分表单上传到服务器。表单中有一个 MD5 哈希字段和一个音频文件字段。

问题是,有时上传的音频文件在文件末尾有换行符,而客户端的原始文件中不存在换行符。这当然会导致 MD5 哈希检查失败。

我很惊讶这种情况只是偶尔发生。在 200 个请求中,有一个请求存在所描述的问题。

这是我的 HttpMultipartFormSender 类的代码:

public class HttpMultipartFormSender
{
    private HttpRequestMessage _requestMessage;

    public HttpMultipartFormSender(string requestUri)
    {
        UploadProgressHandler = new ProgressMessageHandler();
        var boundary = "----------" + DateTime.Now.Ticks.ToString("x", CultureInfo.InvariantCulture);
        Content = new MultipartFormDataContent(boundary);
        _requestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri);
    }

    public MultipartFormDataContent Content { get; set; }

    public ProgressMessageHandler UploadProgressHandler { get; }

    public async Task<bool> SendFormAsync()
    {
        _requestMessage.Content = Content;
        var client = HttpClientFactory.Create(UploadProgressHandler);
        client.Timeout = TimeSpan.FromMinutes(30);

        var httpResponse = await client.SendAsync(_requestMessage); …
Run Code Online (Sandbox Code Playgroud)

c# multipartform-data

8
推荐指数
1
解决办法
735
查看次数

检查 C# 中是否安装了 Powershell 模块

是否可以检查 C# 中是否安装了 powershell 模块?

如果模块已/或未安装,我需要一个 C# 条件。

我知道如何在 C# 中使用 powershell,但如何成为 Powershell 的响应?

感谢您阅读我的问题,我希望任何人都可以给我一些提示。

c# powershell

2
推荐指数
1
解决办法
999
查看次数

将命令行参数传递给控制台应用程序不起作用

我无法将参数传递给我的控制台应用程序。我是这样试的:

App.exe arg1
App.exe "arg1"
App.exe
Run Code Online (Sandbox Code Playgroud)

当我使用参数运行应用程序时,应用程序将退出运行,没有任何消息。

调试时没有任何内容string[] args

我的 C# 项目是一个普通的 .net 4.5.2 命令行项目。我的操作系统是 Windows 10 x64。

示例代码:

using System;
using System.Collections.ObjectModel;
using System.Management.Automation;

namespace Setup
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                using (PowerShell psInstance = PowerShell.Create())
                {
                    string cmd = "Set-ExecutionPolicy RemoteSigned -Force; " +
                                 "echo \"Set-ExecutionPolicy RemoteSigned -Force\"; echo \"\"; " +
                                 "Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force; ";

                    psInstance.AddScript(cmd);

                    Collection<PSObject> PSOutput = psInstance.Invoke();

                    Console.WriteLine(psInstance.Streams.Error[0].ErrorDetails.Message);

                    foreach (var …
Run Code Online (Sandbox Code Playgroud)

c# console-application command-line-arguments

-1
推荐指数
1
解决办法
2万
查看次数