使用C#httpwebrequest发送请求到tiktok
我似乎只有使用C#中的HTTPWebrequest模块向Tiktok主页提出基本请求的问题。这是我的代码。
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://tiktok.com");
using (HttpWebResponse response = (HttpWebResponse)(request.GetResponse()))
{
Console.WriteLine("Done");
}
当我这样做时,该程序将悬挂一段时间,然后我将在下面详细介绍System.NET.WebException。我已经尝试设置用户代理和超时,但两者似乎都无法正常工作。对此的任何帮助将不胜感激。
system.net.webexception hresult = 0x80131509消息=基础连接已关闭:在一个上发生了意外错误 收到。 Source = System StackTrace:at system.net.httpwebrequest.getResponse()in f:\ dd \ ndp \ fx \ src \ net \ net \ net \ net \ httpwebrequest.cs:line 2293 at live.program.main(字符串[] args) 733
这个例外最初是在此通话堆栈中抛出的: system.net.sockets.networkstream.read(byte [],int,int,int)
内部异常1:IOException:无法从传输中读取数据 连接:连接尝试失败,因为连接方 一段时间后没有正确响应或建立 连接失败,因为连接的主机无法响应。
内部异常2:socketException:连接尝试失败 因为互联方在一段时间后没有得到适当的回应 时间或建立连接失败,因为连接的主机有 无法响应
I seem to be having issues just making a basic request to the TikTok homepage using the HttpWebRequest module in C#. Here is my code.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://tiktok.com");
using (HttpWebResponse response = (HttpWebResponse)(request.GetResponse()))
{
Console.WriteLine("Done");
}
When I do this, the program hangs for a while, then I get a System.Net.WebException detailed below. I've tried setting user agents and timeouts but both don't seem to work. Any help on this would be appreciated.
System.Net.WebException HResult=0x80131509 Message=The underlying connection was closed: An unexpected error occurred on a
receive. Source=System StackTrace: at
System.Net.HttpWebRequest.GetResponse() in
f:\dd\NDP\fx\src\net\System\Net\HttpWebRequest.cs:line 2293 at
Live.Program.Main(String[] args) in E:\git\batch\live\Program.cs:line
733This exception was originally thrown at this call stack:
System.Net.Sockets.NetworkStream.Read(byte[], int, int) in NetworkStream.csInner Exception 1: IOException: Unable to read data from the transport
connection: A connection attempt failed because the connected party
did not properly respond after a period of time, or established
connection failed because connected host has failed to respond.Inner Exception 2: SocketException: A connection attempt failed
because the connected party did not properly respond after a period of
time, or established connection failed because connected host has
failed to respond
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不完全确定为什么,但是一旦您
在得到响应之前就这样做,问题就会消失。我尝试使用不同的
用户代理
标题,但我总是暂停。仅.NET Framework Test Client
对我有用。我希望至少对您有所帮助。
I'm not entirely sure why, but once you do
before getting the response, the problem goes away. I tried with different
User-Agent
headers but I always get the timeout. Only.NET Framework Test Client
works for me.I hope that helps you at least a bit.