有一个bug in the ReadAsStringAsync method可以阻止阅读类似foreach($CDNA_new as $t){
$match = "NA";
# Go through the specie array
foreach ($csv_specie as $c){
# Find specie in string
if (strpos($t, $c) !== FALSE ){
$match = $c;
break;
}
}
echo "----------------------". "<br \>\n";
echo '+'.$match. "<br \>\n";
echo '+'.$t. "<br \>\n";
# Work further with the values to retrieve gene ID using eSearch
}
的内容类型。它看起来还没有框架修复它,但有没有解决办法?
答案 0 :(得分:1)
在阅读回复之前,您需要删除引号:
var contentType = response.Content.Headers.ContentType;
if (contentType.CharSet?.Contains('"') == true) {
contentType.CharSet = contentType.CharSet.Replace("\"", "");
}
这是我正在使用的完整DelegatingHandler:
public class StripCharSetQuotesHandler : DelegatingHandler
{
public StripCharSetQuotesHandler(HttpClientHandler innerHandler) {
: base(innerHandler)
{
// Nothing additional.
}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
var response = await base.SendAsync(request, cancellationToken);
var contentType = response.Content.Headers.ContentType;
if (contentType.CharSet?.Contains('"') == true) {
contentType.CharSet = contentType.CharSet.Replace("\"", "");
}
return response;
}
}
您希望确保尽可能靠近HttpClientHandler
删除引号,这就是构造函数接受HttpClientHandler
而不是HttpMessageHandler
的原因。