我正在调用网络api来发布一些图像,其中有两个参数
ActionId => int,
Images => [{"content":"base64","mime":"image/png"}]
当base64太大时,请求中会省略该参数
public static async Task<ImageResponseModel> UploadFile(List<ApiParameters> lstParameters, string url)
{
try
{
string boundary = "---boundaryb5dafaaadaad";
MultipartFormDataContent form = new MultipartFormDataContent(boundary);
foreach (var par in lstParameters)
{
form.Add(new StringContent(par.ParameterValue), par.ParameterName);
}
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("postman-token", "fe10d2c6-201e-ca7d-0d66-52d7f948f78f");
client.DefaultRequestHeaders.Add("cache-control", "no-cache");
client.DefaultRequestHeaders.Add("authorization", "the auth token here");
HttpResponseMessage response = await client.PostAsync(ServerUrl + url, form);
response.EnsureSuccessStatusCode();
client.Dispose();
string responseContent = await response.Content.ReadAsStringAsync();
var apiResponse = JsonConvert.DeserializeObject<ImageResponseModel>(responseContent);
return apiResponse;
}
catch (Exception ex)
{
Log.Report(ex);
return null;
}
}
StringContent
无法处理大块文本(+ 2MB图像,字符串长度超过600万个字符)吗?