【问题标题】:HttpClient Response Message SizeHttpClient 响应消息大小
【发布时间】:2012-07-23 18:53:06
【问题描述】:

我有一个 webapi

public ISearchProviderCommandResult ExecuteCommand(ISearchProviderCommand searchCommand)
{
  //serialize the object before sending it in
  JavaScriptSerializer serializer = new JavaScriptSerializer();
  string jsonInput = serializer.Serialize(searchCommand);

  HttpClient httpClient = new HttpClient() { BaseAddress = new Uri(ServiceUrl), MaxResponseContentBufferSize = 256000 };

  StringContent content = new StringContent(jsonInput, Encoding.UTF8, "application/json");

  HttpResponseMessage output = httpClient.PostAsync(ServiceUrl, content).Result;

  //deserialize the output of the webapi call
  SearchProviderCommandResult searchResult = serializer.Deserialize<SearchProviderCommandResult>(output.Content.ReadAsStringAsync().Result);

  return searchResult;
}

在我的本地机器上,无论我是否设置 MaxResponseContentBufferSize,它似乎都以我想要的方式检索数据。但是在我们的构建环境中,如果我不设置 MaxResponseContentBufferSize ,我会收到此错误: 无法向缓冲区写入超过配置的最大缓冲区大小的字节数:65536。

在 google 上查看后,我决定将 MaxResponseContentBufferSize 设置为任意 256000 值。即使这在我的本地机器上有效,但在构建框上我收到此错误: 找不到方法:'无效 System.Net.Http.HttpClient.set_MaxResponseContentBufferSize(Int64)

我现在不知道该怎么办。

【问题讨论】:

  • 这段代码是干什么用的?对于 ASP.NET 应用程序或任何其他应用程序?
  • 是的,它的 asp.net web api 代码。我们根据我在 Anand 的帖子中的 cmets 解决了这个问题。

标签: httpclient asp.net-mvc-4 asp.net-web-api


【解决方案1】:

查看forums.asp.net 上的此线程。您的构建环境中的 .net 4.5 beta 版本似乎存在一些问题。您的本地和构建环境肯定存在 dll 不匹配

【讨论】:

猜你喜欢
  • 2020-02-13
  • 2013-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-02
  • 2015-03-06
相关资源
最近更新 更多