【问题标题】:send query string more than two hundred thousand characters in json to api - c #将json中超过20万个字符的查询字符串发送到api-c#
【发布时间】:2015-06-26 10:04:34
【问题描述】:

我想发送一个由 json 转换为 base64 的 jpeg 图像。图像大小约为 660kb,转换后的字符长度约为 200 万。我需要将它发送到 api ?如果可能,在查询字符串中。

我得到的错误是字符串太长。有其他选择吗?

        HttpClient client = new HttpClient();
        string uploadJson = "http://mylink/WebApi/api/uploadPhoto?jsonImage=" + jsonImage + "&IdOdl=" + IdOdl + "&SnDevice=" + SnDevice + "&cod=" + cod + "&IdTechnician=" + IdTechnician + "&id_producer=" + id_producer + "&pdr=" + pdr;

        client.BaseAddress = new Uri(uploadJson);
        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        Task<HttpResponseMessage> response = client.GetAsync(uploadJson);
        HttpResponseMessage res = response.Result;
        if (!res.IsSuccessStatusCode)
        {
            Console.Write("Error upload");
        }

【问题讨论】:

  • 根据您收到的确切错误消息,无论是客户端还是服务器端,这可能会有所不同。但是,显而易见的方法是在正文中发布图像文件,而不是通过查询字符串执行 GET。

标签: c# json asp.net-web-api query-string


【解决方案1】:

你想做的事是不可能的。

如果您查看RFC for the standard itself,URL/查询字符串的长度不可能那么长。大多数实现将它们截断大约 2k 个字符,超过的任何内容都需要通过 POST 发送。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    • 2010-10-13
    • 1970-01-01
    相关资源
    最近更新 更多