如何从服务器获取中间响应?

发布于 2024-08-10 10:23:33 字数 491 浏览 7 评论 0原文

我正在尝试检查用户输入的 pop 和 smtp 值。我希望验证用户输入的 pop 和 smtp 例如(pop.gmail.com,smtp.gmail.com)是正确还是错误。

为此,我仅通过获取用户输入的 pop 和 smtp 值向服务器发送一个请求,这将执行两项任务 1. 通过连接到该特定服务器来检查用户输入的 pop, 2. 通过向某个虚拟邮件 ID 发送 1 封邮件来检查用户输入的 smtp。 我完成了所有这些任务..

但是现在我的要求是,我必须在验证每件事后向用户显示..我的意思是在ui中我必须显示为

  1. POP连接已检查..好的
  2. smtp连接已检查..好的这样。

但是我只向服务器发送了一个请求来完成这两项任务。所以我需要在完成每项任务后从服务器获取中间状态。所以只有我可以在客户端用户界面中更新。但我不知道是否可能从服务器获取单个请求的中间响应...朋友们有什么想法吗?如果是这样,你能想出一些代码......

期待建议吗?

I am trying to check pop and smtp values entered by user.. I wish to validate that pop and smtp say for example(pop.gmail.com,smtp.gmail.com) which is entered by user is correct or wrong.

For that I am sending only one request to server by taking both pop and smtp values entered by user which will do two tasks
1. Checks user entered pop by making connection to that particular server ,
2. Checks user entered smtp by sending 1 mail to some dummy mail id..
I finished all these tasks..

But now what my requirement is, I have to show the user after validating each thing.. I mean in ui i have to show as

  1. POP connection Checked.. ok
  2. smtp connection Checked.. ok like that.

But i sent only one request to server for doing both these tasks..So i need to get intermediate status from server after finishing each tasks..So only i can update in client side UI.. But i don't know is it possible to get intermediate responses from server for a single request... Any idea friends? If so can you come up with a little bit of code...

Expecting the suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

清晰传感 2024-08-17 10:23:33

你应该看看长轮询技术,它可以检索部分响应,但它不适用于所有浏览器。

you should take a look in the long polling technique, it is possible to retrieve partial response but it doesn't work on all browsers.

对你的占有欲 2024-08-17 10:23:33

您可以使用 HEAD 请求代替仅返回 HTTP 标头的 GET 或 POST

You can use HEAD request instead of GET or POST which only return HTTP header

み青杉依旧 2024-08-17 10:23:33

有点偏离主题 - 但发送虚拟邮件可能是“危险的”。

如果您尝试发送到不存在的本地地址,许多服务器会“注意到”。例如 - 如果服务器的域是“whatever.com”并且您发送到随机地址,请说 [email protected],并且“aaa”不是有效用户,那么服务器会注意到这一点。

然后,服务器可能采取措施,例如在一段时间内阻止您作为发件人。 (这有助于减少字典攻击造成的垃圾邮件。)因此,您的“测试”最终会有效地阻止真实邮件的传递。

反之亦然。假设您尝试发送到一个您知道有效的外部地址(例如您自己的电子邮件地址)作为测试。在这种情况下,发件人地址必须是有效的内部地址。如果您使用无效的内部地址,或者更糟糕的是非内部地址,服务器可能会拒绝投递邮件(最好的情况是),最坏的情况会再次建立临时阻止。

这两种情况的关键因素是,虽然 SMTP 协议非常“宽松”,但 SMTP 服务器非常密切地监视“不良行为”,因为这是区分垃圾邮件程序的一种方法。因此,任何隐藏“不正确”行为都可能导致它任意拒绝接受您的邮件(通常在有限的时间内)。

顺便说一句,回到您最初的问题。
您的两项测试几乎都是即时的。即使电子邮件服务器位于世界的另一端,您也可以在几秒钟内完成这两项检查。因此,即使您发回 2 个数据包,对于用户来说,它们也会显示为“一起到达”。由于来自浏览器的 1 个请求只能处理来自服务器的 1 个响应,因此您需要以 2 个数据包发送响应。

即进行第一次测试 - 发送响应的第一部分 - 进行第二次测试 - 发送响应的第二部分。

对于普通的 HTTP 数据包来说这没什么大不了的。在第一个响应准备好后进行某种刷新/发送,然后在第二个响应后再次进行。浏览器习惯于在部分页面到达时显示它们。

然而,对于 AJAX 请求,您需要在相当低的级别上进入您的框架。据我所知,大多数框架都要求传入的异步数据包在开始解析之前是“完整的”。如果数据包的格式为 xml(其中部分解析在几乎所有情况下都是无用的),则尤其如此。

Slightly off topic - but sending a dummy mail can be "dangerous".

Many servers "note" if you try and send to a local address, which does not exist. For example - if the server's domain is "whatever.com" and you send to a random address, say [email protected], and "aaa" is not a valid user, then the server notices this.

The server may then take an action like blocking you, as a sender, for a period of time. (This helps to reduce spam from dictionary attacks.) So your "test" ends up effectively blocking the real mail from being delivered.

The reverse is also true. Let's say you try to send to an external address, which you know is valid (your own email address for example) as the test. In this case the from address must be a valid internal address. If you use an invalid internal address, or worse an address which is not internal, it's likely the server will refuse to deliver the mail (at best) and at worst again institute a temporary block.

The key factor in both these situations is that although the SMTP protocol is very "loose", SMTP servers watch very closely for "bad behavior" because this is one way of distinguishing a spamming program. So any hide of "incorrect" behavior can lead to it arbitrarily refusing to accept your mails (usually for a limited period of time.)

Incidentally, back to your original question.
Both of your tests are pretty much instantaneous. Even if the email server is on the other side of the world you can do both checks inside a couple seconds. So chances are even if you send back 2 packets, to the user they'll appear as "arriving together". And since 1 request from the browser can only handle 1 response from the server you would need to send the response in 2 packets.

ie do first test - send first part of response - do second test - send second part of response.

For a normal HTTP packet this is no big deal. Do some sort of flush / send after the first response is ready, and then again after the second response. The browser is used to displaying partial pages as they arrive.

However for an AJAX request you'll need to get into your framework at quite a low level. Most frameworks, that I'm aware of, require the incoming Async packet to be "complete" before they start to parse it. This is especially true if the packet is formatted as say xml where partial parsing is useless in pretty much all cases.

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