Jump to content

I have a problem with login the site from c# desktop application

- - - - -

  • Please log in to reply
14 replies to this topic

#1
hers19

hers19

    Newbie

  • Members
  • Pip
  • 8 posts
Help me, please

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
You have to give us some details about your problem.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
hers19

hers19

    Newbie

  • Members
  • Pip
  • 8 posts
I want to login to http://bakcell.com/en/login and with the same session to do other operations. I succesfully applied this to other sites. I use HttpWebRequest and Cookie Container. So i can not apply it to http://bakcell.com/en/login. When i try to login the site responses "crf tooken" error.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Again, we need more information. You haven't shown the code that's failing.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
hers19

hers19

    Newbie

  • Members
  • Pip
  • 8 posts
that is it:

---------------------------------------
CookieContainer cc = new CookieContainer();
string param = "signin[username]=" + login + "&signin[password]=" + pass + "&signin[_csrf_token]=e23ad9640c73afdf4995c2781e0b699e";
string url="http://bakcell.com/en/login";
ASCIIEncoding encoding = new ASCIIEncoding();

byte[] byteData = System.Text.Encoding.UTF8.GetBytes(param);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentLength = byteData.Length;
request.ContentType = "application/x-www-form-urlencoded";
request.CookieContainer = cc;
Stream s = request.GetRequestStream();
s.Write(byteData, 0, byteData.Length);
s.Close();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
receiveData = response.GetResponseStream();

#6
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
You always use the same csrf_token value. I've accessed the web page you use and I've seen that this token changes every time you try to login. You cannot use the same value for all connections. Maybe this token is assigned to your session the first time you access, and is valid until the session expires. You should try to get the current token value before sending the login request.

#7
hers19

hers19

    Newbie

  • Members
  • Pip
  • 8 posts
I have tried to get it with this code:

WebRequest wr = WebRequest.Create("http://bakcell.com/en/login");
WebResponse rs = wr.GetResponse();
Stream s = rs.GetResponseStream();
StreamReader srt = new StreamReader(s);
receiveData = srt.ReadToEnd();
string csrf = receiveData.Substring(receiveData.IndexOf("signin[_csrf_token]"), 32);


But when i request the server occur this error: The remote server returned an error: (401) Unauthorized. i cant understand when i request with webBrowser it responses normally but when i request from my windows application it responses 401 error code

#8
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
By the way, do you have permission to do an automated login to this site ? does this site belong to you ? this doesn't seem the good way to access resources from a program. Normally there should be another interface (WebServices or something like that) for application access if it's permited...

The 401 answer is right. You are not authenticated, so you are not authorized to access and the server sends the login page after the 401 error. Browsers also receive the same answer.

#9
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 242 posts
They are probably looking at the requester information (what browser, what os) and determining that you are not a known browser type, thus rejecting you. You'll probably have to modify the User-Agent string. You'll need to use the HttpWebRequest (I believe) to change this.

#10
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
I don't think this is the problem. If I request the login page from Firefox, I also get a 401 error. However, the content of the error page is, in fact, the login form.

#11
hers19

hers19

    Newbie

  • Members
  • Pip
  • 8 posts
no, i dont have permission and it does not belong to me. I think so, for this using WebServices is better way but there is not any public interface for this in the site that is why i try this method.

But why server does not send login page to application and is there any way to request as same as browser?

#12
hers19

hers19

    Newbie

  • Members
  • Pip
  • 8 posts
i have modified the User-Agent string but it doesnt help... i get same result as before




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users