What do Threads share when making Http calls?

Asked

Viewed 100 times

3

The problem: I can’t login to a site more than once on Threads different.

My application is a Console application.
If I open several executable, can each do successfully login in one Thread, only the first. I believe this excludes several problems I might have related to the site I am accessing, because the various Consoles open use the same credentials (user), are running on the same machine and are opened at the same time. Therefore the site allows more than one session on the same user.

I’m using the same solution to various websites and her worked for the most part I had to do it. The sites have no relation to each other and I do not care which technology they use(I do not think pertinent, but I can check if it is necessary).

As Threads are initiated with new Thread(IniciaTarefa).Start(argumentos);. The method IniciaTarefa is static, but inside it instantiates another class that has nothing static. And it is this other class that makes the requests.

Each request is instantiated a new request = WebRequest.Create(url) as HttpWebRequest;, despite all the requisitions of the same Thread share the same CookieContainer to maintain the session.

I accept any hint about what I can investigate, because I have no idea what the problem might be, I have reviewed and tried to make several changes to the code, but the problem persists.
If I have to, I can put in specific code snippets, but I don’t know what might be pertinent.

  • 1

    Have you checked whether there are differences in the requests for each thread using any outside programs? Like Fiddler? http://www.telerik.com/fiddler The problem is very open, it can be many things each site can manage the authentication in different ways...

1 answer

0

The problem is the CookieContainer that is being shared by Threads... When you log in, the site you log in to records a cookie in your browser (in this case, the cookie is recorded in Cookiecontainer) and it is through it that the site can identify that you are you, From what you have said, Cookiecontainer is being reused by the various Threads of the same process, making the login occur in the first and the second from the site already identify that you are logged in exactly for the reason of reusing the cookieContainer. Try creating a CookieContainer by request, just as you do with WebRequest.Create

Browser other questions tagged

You are not signed in. Login or sign up in order to post.