我正在尝试使用Web-APi 2和protobuf-net发送对象。我一直收到404错误,所以我假设路由出了问题?
当我注释掉序列化行
时ProtoBuf.Serializer.Serialize(memstream, package);
(因此内存流保持为空)路由工作并调用RecievePackage。 package参数为空。 (包对象本身不是NULL,但它的所有属性都是。)
每当内存流不为空时,我都会收到404错误。我在这里做错了什么?
接收代码:
[Route("Receive")]
[HttpPost]
public async Task<IHttpActionResult> RecievePackage(PackageModel package)
{
id = await SavePackage(package);
return Created("", id);
}
发送代码:
private async Task SyncUpAsync(string apiUrl, PackageModel package)
{
using (HttpClient client = new HttpClient())
using (var memstream = new MemoryStream())
{
var uri = new Uri(new Uri(ApiUrl), apiUrl);
ProtoBuf.Serializer.Serialize(memstream, package);
memstream.Position = 0;
var content = new StreamContent(memstream);
content.Headers.Add("SyncApiToken", ApiKey);
content.Headers.Add("Content-Type", "application/x-protobuf");
var response = await client.PostAsync(uri, content);
}
}