What Threads do you share when making Http calls?

3

Problem: I can not log in to a site more than once in%% of different%.

My application is Threads . If I open multiple executable , each can login successfully on a Console application , only the first . I believe this excludes a number of problems that I might have related to the site I'm accessing, since the various% open% coopes use the same credentials (user), are running on the same machine and are opened at the same time. So the site allows more than one session on the same user.

I'm using same solution for multiple sites and it worked for the majority I needed to do this. The sites have no relation to each other and I do not care what technology they use (I do not think it's relevant, but I can check if it's necessary).

The Thread is started with Consoles . The Threads method is static, but inside it instantiates another class that has nothing static. And it's this other class that makes the requisitions.

Each request is instantiated a new new Thread(IniciaTarefa).Start(argumentos); , although all requests of the same IniciaTarefa share the same request = WebRequest.Create(url) as HttpWebRequest; to keep the session.

I accept any tips on what I can investigate, because I have no idea what the problem might be, I have already reviewed and tried to make several changes to the code, but the problem persists. If need be I can put specific code snippets, but I do not know what might be relevant.

    
asked by anonymous 26.05.2016 / 01:38

1 answer

0

The problem is CookieContainer being shared by Threads ... When you log in, the site you access records a cookie in your browser (in this case, the cookie is saved in the CookieContainer) and it is through it that the site can identify who you are, from what you said, CookieContainer is being reused by several Threads of the same process, causing the login to occur in the first and second on the site already identifies that you are logged in exactly for the reason of reusing the cookieContainer. Try to create a CookieContainer per requisition, just like you do with WebRequest.Create

    
10.01.2017 / 05:27