我有一个Asp.Net Core 2.0 Web API服务,其HTTP Post
方法包含byte[]
参数,当较大的JSON(~30MB)作为正文内容发送时,该参数无法反序列化,因此具有null
值。对于较小的JSON,它能够正确地反序列化为byte[]
数组。
基本上我要做的是将byte[]
发送到Asp.Net Core 2.0 Web API端点,该端点将此有效负载作为Azure中的blob存储上载。以下是API和调用代码的代码。
请注意payload
参数具有空值:
public class MyBlobController : Controller
{
[HttpPost("UploadPayload/{containerName}/{blobName}")]
public async Task<string> UploadPayload([FromBody] byte[] payload,
string containerName, string blobName)
{
//code for uploading blob
}
}
调用此端点的代码:
var jsondata = JsonConvert.SerializeObject(payloadData); //payload is large byte array
HttpContent content = new StringContent(jsondata, Encoding.UTF8, "application/json");
//Instantiating the HttpClient.
{
var HttpClientInstance = new HttpClient();
HttpClientInstance.DefaultRequestHeaders.Clear();
HttpClientInstance.DefaultRequestHeaders
.AcceptLanguage.Add(new StringWithQualityHeaderValue("nl-NL"));
HttpClientInstance.DefaultRequestHeaders
.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
HttpResponseMessage apiResponse = null;
//Sending a post request to the Blob Api.
apiResponse = await HttpClientInstance
.PostAsync("http://localhost:8999/api/MyBlob/UploadPayload/mycontainer/myblob", content);
我还经历了这个GitHub Issue,它告诉我们如何更改HTTP Post
请求的最大限制大小。我也启用了这个设置,以便能够接受大量请求,但反序列化仍然没有运气。