简体   繁体   English

TIdHTTP.Get() 返回空字符串

[英]TIdHTTP.Get() returns blank string

I'm facing a weird issue in which the Get() method of TIdHTTP on a valid URL is returning a blank string, but only on specific machines.我面临一个奇怪的问题,其中有效TIdHTTP上的 TIdHTTP 的Get()方法返回一个空白字符串,但仅在特定机器上。 Also, in these same machines, if I navigate to the same URL in Google Chrome, it will return the expected value.此外,在这些相同的机器上,如果我在 Google Chrome 中导航到相同的 URL,它将返回预期值。

No exception occurs, just an empty string is returned.不会发生异常,只返回一个空字符串。 Tried both HTTPS and HTTP versions of the URL, and the same problem happens.尝试了 URL 的 HTTPS 和 HTTP 版本,同样的问题发生了。 Also tried using the CookieManager and setting HandleRedirects to true, no luck.还尝试使用CookieManager并将HandleRedirects设置为 true,没有运气。

The machine in question is Windows 2012 server, and my app is whitelisted on its firewall.有问题的机器是 Windows 2012 服务器,我的应用程序在其防火墙上被列入白名单。

Is there anything I could try to diagnose / fix this issue?有什么我可以尝试诊断/解决这个问题的吗? I'm lost !我迷路了 !

Unfortunately, there is not enough information provided to diagnose what is happening.不幸的是,没有提供足够的信息来诊断正在发生的事情。 Since there is no exception being raised, there are only two possibilities.由于没有引发异常,因此只有两种可能性。 Either:任何一个:

  • the server really is sending blank body data, such as if you are using Indy's default UserAgent and the server does not like/recognize it.服务器确实在发送空白正文数据,例如,如果您使用 Indy 的默认UserAgent并且服务器不喜欢/识别它。 Some servers are UserAgent-aware and will deliver different data for different agents.一些服务器是 UserAgent 感知的,将为不同的代理提供不同的数据。 Try setting the TIdHTTP.Request.UserAgent property to mimic a real web browser, see if the result changes.尝试设置TIdHTTP.Request.UserAgent属性以模仿真实的 web 浏览器,看看结果是否改变。

  • the server is sending body data, but the data is getting lost when converted to a String , such as due to an invalid charset conversion.服务器正在发送正文数据,但在转换为String时数据会丢失,例如由于无效的字符集转换。 TIdHTTP.Get() has an overload that fills a TStream instead of return a String , you can use that to rule out any issue with charset handling. TIdHTTP.Get()具有填充TStream而不是返回String的重载,您可以使用它来排除字符集处理的任何问题。

I suggest you look at the raw HTTP traffic to make sure the request and response are what you are expecting them to be.我建议您查看原始 HTTP 流量,以确保请求和响应符合您的预期。 To capture the raw data, you can use a packet sniffer, like Wireshark.要捕获原始数据,您可以使用数据包嗅探器,例如 Wireshark。 Or assign one of Indy's TIdConnectionIntercept -derived components, like TIdLog... , to the TIdHTTP.Intercept property.或者将 Indy 的TIdConnectionIntercept派生组件之一(如TIdLog... )分配给TIdHTTP.Intercept属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM