使用C#httpwebrequest发送请求到tiktok

发布于 2025-02-03 20:07:15 字数 966 浏览 4 评论 0原文

我似乎只有使用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
733

This exception was originally thrown at this call stack:
System.Net.Sockets.NetworkStream.Read(byte[], int, int) in NetworkStream.cs

Inner 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南七夏 2025-02-10 20:07:15

我不完全确定为什么,但是一旦您

request.UserAgent=".NET Framework Test Client";

在得到响应之前就这样做,问题就会消失。我尝试使用不同的用户代理标题,但我总是暂停。仅.NET Framework Test Client对我有用。
我希望至少对您有所帮助。

I'm not entirely sure why, but once you do

request.UserAgent=".NET Framework Test Client";

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文