开发者

How to get intermediate response from server?

开发者 https://www.devze.com 2022-12-11 04:39 出处:网络
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.

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?


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.


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


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 aaa@whatever.com, 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消