size limit workaround for FormUrlEncodedContent

后端 未结 2 699
执念已碎
执念已碎 2021-01-19 06:20

I\'m receiving the error:

System.UriFormatException: Invalid URI: The Uri string is too long.

The problem is with this line:



        
2条回答
  •  清歌不尽
    2021-01-19 06:43

    If your request is larger use multipart/form-data instead:

    using (var content = new MultipartFormDataContent())
    {
        foreach (var keyValuePair in data)
        {
            content.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);
        }
    
        // send POST request
        using (var client = new HttpClient())
        {
            return client.PostAsync(identifier.IsirUrl + uri, content).GetAwaiter().GetResult();
        }
    }
    

提交回复
热议问题