Discussion:
Simulate a Post
(too old to reply)
Leandro Delamare
2004-11-22 13:45:41 UTC
Permalink
Hello Newsgroup

I have a question, I saw this article How to simulate a Form POST request by
using WinInet
http://support.microsoft.com/default.aspx?scid=kb;EN-US;165298, and this is
something like a need.

But, I need to make the post in 3 diferent servers, and need a result with
the faster server..

Someone can help me to how make this ?

Regards
Stephen Sulzer
2004-11-24 00:45:05 UTC
Permalink
Can you explain again what you what to do? To me, it sounds like you want
to send the same request to 3 different servers in parallel, receive the
response from the server that responds first ("the faster server"), and
discard (stop waiting for) the responses from the other two servers.
Leandro Delamare
2004-11-24 11:25:37 UTC
Permalink
Yes,
How can I do this ?
Can you send and sample code ?

Regards
Post by Stephen Sulzer
Can you explain again what you what to do? To me, it sounds like you want
to send the same request to 3 different servers in parallel, receive the
response from the server that responds first ("the faster server"), and
discard (stop waiting for) the responses from the other two servers.
Stephen Sulzer
2004-11-25 11:00:18 UTC
Permalink
I do not have any sample code for this.

There are two ways to send requests in parallel:

1) Create separate worker threads and have each thread send a synchronous
HTTP request to one of the servers. Or instead of creating your own threads,
you can use the system thread pool with the QueueUserWorkItem Win32 API.

2) Use WinInet in asynchronous mode and dispatch the multiple requests from
your main client thread. WinInet will use the system thread pool to process
the requests concurrently.

In each case, once one of the requests has received a response, you can then
abort the other requests (or just let them finish and ignore/discard the
responses they receive). You need to decide at what point a request has
received a response and should tell the other requests to abort. For
example, when all of the response data has been received? Or, when the first
part of the response data has been received? Or when just the HTTP response
headers have been received? If you do not expect a large response, then it
does not matter how you decide this.

Both solutions involve multi-threaded programming, which you need to
understand. You will need a global flag (with synchronized write access
using InterlockedIncrement, for example) that is set once one of the
requests has received a response. Each request can use this flag to see if
some other request has finished already, and if so, it can then abort itself
(by closing its WinInet request and connect handles) and discard any
response data it has received.

Solution #1 is probably easier to implement (since using WinInet in
asynchronous mode can be difficult). It is also important to point out that
WinInet should only be used in a single-user application. Do not use WinInet
in any kind of multi-user, server-based application, such as a proxy server
or within an ISAPI component. For server-based applications, use WinHTTP
instead.

If you try solution #2, and you are not familiar with using WinInet in
asynchronous mode, then read the following documentation to help get you
started:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/asynchronous_operation.asp

Good luck.

Stephen
Leandro Delamare
2004-11-26 12:06:07 UTC
Permalink
Stephen, I'm not a great C++ programmer.
Then if you can write here a sample of code to do this for me .... :)
Regards
Post by Stephen Sulzer
I do not have any sample code for this.
1) Create separate worker threads and have each thread send a synchronous
HTTP request to one of the servers. Or instead of creating your own threads,
you can use the system thread pool with the QueueUserWorkItem Win32 API.
2) Use WinInet in asynchronous mode and dispatch the multiple requests from
your main client thread. WinInet will use the system thread pool to process
the requests concurrently.
In each case, once one of the requests has received a response, you can then
abort the other requests (or just let them finish and ignore/discard the
responses they receive). You need to decide at what point a request has
received a response and should tell the other requests to abort. For
example, when all of the response data has been received? Or, when the first
part of the response data has been received? Or when just the HTTP response
headers have been received? If you do not expect a large response, then it
does not matter how you decide this.
Both solutions involve multi-threaded programming, which you need to
understand. You will need a global flag (with synchronized write access
using InterlockedIncrement, for example) that is set once one of the
requests has received a response. Each request can use this flag to see if
some other request has finished already, and if so, it can then abort itself
(by closing its WinInet request and connect handles) and discard any
response data it has received.
Solution #1 is probably easier to implement (since using WinInet in
asynchronous mode can be difficult). It is also important to point out that
WinInet should only be used in a single-user application. Do not use WinInet
in any kind of multi-user, server-based application, such as a proxy server
or within an ISAPI component. For server-based applications, use WinHTTP
instead.
If you try solution #2, and you are not familiar with using WinInet in
asynchronous mode, then read the following documentation to help get you
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/asynchronous_operation.asp
Good luck.
Stephen
Continue reading on narkive:
Loading...