将 json 中超过二十万个字符的查询字符串发送到 api - c#

send query string more than two hundred thousand characters in json to api - c #

我想发送由 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");
        }

你想做的事是不可能的。

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