【发布时间】:2019-11-29 00:28:01
【问题描述】:
我正在使用 YoutubeExplode 代理从 youtube.com 下载视频。
public async Task<ApiResult<List<videoList>>> Search(string videoName)
{
var res= new ApiResult<List<videoList>>(0,null,null);
//set proxy
HttpClientHandler handler = new HttpClientHandler()
{
Proxy = new WebProxy("myvps:port",false),
UseProxy = true
};
using (var client = new HttpClient(handler))
{
YoutubeClient youtubeclient = new YoutubeClient(client);
var list=await youtubeclient.SearchVideosAsync(videoName, 2);
//convert
res.data = list.ToVideoList();
}
return res;
}
由于GFW,我带了一个VPS,安装了Squid(一个http代理服务器)并在Ubuntu16.04上像这样简单地配置了它
bash:"sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.original"
bash:"vim /etc/squid/squid.conf"
http_port 3128
http_access allow all
bash:"systemctl restart squid.service"
之后,当我运行 WebApi 时,我收到了错误消息:
<ExceptionMessage>
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
</ExceptionMessage>
我查看了 squid 日志
1563595921.406 2 117.152.169.17 TAG_NONE/500 0 CONNECT youtube.com:443 - HIER_DIRECT/172.217.5.78 -
1563595921.708 0 117.152.169.17 TAG_NONE/500 0 CONNECT youtube.com:443 - HIER_DIRECT/172.217.5.78 -
1563596804.825 3 117.152.169.17 TAG_NONE/500 0 CONNECT youtube.com:443 - HIER_DIRECT/172.217.14.110 -
1563596805.076 0 117.152.169.17 TAG_NONE/500 0 CONNECT youtube.com:443 - HIER_DIRECT/172.217.14.110
我想知道我的配置文件有什么问题。
所以我尝试了 bash:"curl -x vps_ip:port -L https://www.youtube.com",但它似乎奏效了。
查看日志
1563599971.588 2930 xxx_xxx_xxx_xxx TCP_TUNNEL/200 385942 CONNECT www.youtube.com:443 - HIER_DIRECT/172.217.14.110 -
请帮忙!
【问题讨论】:
标签: c# ubuntu-16.04 dotnet-httpclient http-proxy squid