【发布时间】:2015-06-19 05:48:47
【问题描述】:
我有一个 DelegatingHandler 的实现,它基本上接受一个请求并将其发送到另一台服务器 (http://localhost:9999/test/page.php --> http://otherSite.com/test/page.php )。
根据我的问题here,我现在必须阅读页面的结果并进行一些编辑:
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
string url = request.RequestUri.PathAndQuery;
UriBuilder forwardUri = new UriBuilder(_otherWebSiteBase);
forwardUri.Path = url;
HttpRequestMessage newRequest = request.Clone(forwardUri.Uri.ToString());
HttpResponseMessage responseMessage = await _client.SendAsync(newRequest);
//HERE: How to read the responseMessage.Content in string?
return responseMessage;
}
我正在尝试阅读消息的内容,更改其中的某些部分(基本上将所有 http://otherSite.com 更改为 http://localhost:9999 )然后返回。
我面临的问题:
string content =await responseMessage.Content.ReadAsStringAsync();
- 不返回任何可读的内容(我不确定,但我觉得可能是因为压缩?)
- 有没有办法替换邮件内容?
【问题讨论】:
标签: c# .net asp.net-web-api asp.net-web-api2