相关疑难解决方法(0)

HttpClient:uri字符串太长

鉴于以下尝试将数据发布到生成PDF文件的Web服务,PDF rocket(顺便说一句,这很棒).

我收到错误无效的URI:uri字符串太长
为什么有人会对POSTed数据施加任意限制?

using (var client = new HttpClient())
{
    // Build the conversion options
    var options = new Dictionary<string, string>
    {
        { "value", html },
        { "apikey", ConfigurationManager.AppSettings["pdf:key"] },
        { "MarginLeft", "10" },
        { "MarginRight", "10" }
    };

    // THIS LINE RAISES THE EXCEPTION
    var content = new FormUrlEncodedContent(options);

    var response = await client.PostAsync("https://api.html2pdfrocket.com/pdf", content);
    var result = await response.Content.ReadAsByteArrayAsync();
    return result;
}
Run Code Online (Sandbox Code Playgroud)

我收到了这个荒谬的错误.

 {System.UriFormatException: Invalid URI: The Uri string is …
Run Code Online (Sandbox Code Playgroud)

c# dotnet-httpclient

15
推荐指数
4
解决办法
2万
查看次数

如何使用来自 nuget 的 .NET Core 从命令行下载包?

Microsoft在 Linux 上为 Ubuntu打包了.NET Core。我目前正在使用它。我现在想安装Json.NET,它指示我使用包管理器控制台并运行,

PM> Install-Package Newtonsoft.Json
Run Code Online (Sandbox Code Playgroud)

我想知道我是怎么做那个 Linux 的。我看到有一个Nuget CLI,但它似乎在 .NET Core 上不可用。此外,文档说

在 Mac 和 Linux 上,安装 Mono 4.4.2 或更高版本。

如何在 Linux 上简单地安装软件包?npm/cpan/pip/gem 的 .NET 等价物是什么?

当我运行时dotnet nuget,install命令似乎丢失了。

NuGet Command Line 4.3.0.5

Usage: dotnet nuget [options] [command]

Options:
  -h|--help                   Show help information
  --version                   Show version information
  -v|--verbosity <verbosity>  The verbosity of logging to use. Allowed values: Debug, Verbose, Information, Minimal, Warning, Error. …
Run Code Online (Sandbox Code Playgroud)

.net c# linux .net-core .net-core-2.0

4
推荐指数
1
解决办法
3429
查看次数

如何将此字符串拆分为Dictionary <string,string>?

我有以下字符串:

{"key1":"value1","key2":"value2,some other part of value2"}
Run Code Online (Sandbox Code Playgroud)

我可以使用以下长语法来分割它:

var s = someString.Split(new[] {"\",\""}, StringSplitOptions.RemoveEmptyEntries);
var firstEntryValue = s[0].Split(':')[1];
var secondEntryValue = s[1].Split(':')[1];
Run Code Online (Sandbox Code Playgroud)

由于这个字符串基本上是一个Dictionary<string,string>,我怎样才能将整个事物基本上拉成一行?

我见过这样的话:

var s = someString.Split(new[] {"\",\""}, StringSplitOptions.RemoveEmptyEntries)
  .Select(p => p.Split(':'))
  .ToDictionary(split => split[0], split => split[1]);
Run Code Online (Sandbox Code Playgroud)

但它抛出并索引越界错误.是否有一些类似的语法可行?

.net c# string dictionary split

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