Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Arena War
      2. After Hours
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA Next

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
Jitnaught

C# Login to GTA4-Mods.com

Recommended Posts

Jitnaught

So I'm trying to make an app that logs into GTA4-Mods.com, and I can't seem to get it to work with all of the solutions I found from searching on Google. Here is one of the solutions I tried:

using (CookieAwareWebClient client = new CookieAwareWebClient())                    {                        string loginAddress = "http://www.gtagaming.com/gta4mods/login.php?p=/";                        NameValueCollection loginData = new NameValueCollection            {                { "username", tbUser.Text },                { "password", tbPass.Text }            };                        client.Login(loginAddress, loginData);                        string webpageString = client.DownloadString("http://www.gta4-mods.com/");                        ... other code...}

The CookieAwareWebClient class is:

public class CookieAwareWebClient : WebClient    {        public void Login(string loginPageAddress, NameValueCollection loginData)        {            CookieContainer container;            var request = (HttpWebRequest)WebRequest.Create(loginPageAddress);            request.Method = "POST";            request.ContentType = "application/x-www-form-urlencoded";            var buffer = Encoding.ASCII.GetBytes(loginData.ToString());            request.ContentLength = buffer.Length;            var requestStream = request.GetRequestStream();            requestStream.Write(buffer, 0, buffer.Length);            requestStream.Close();            container = request.CookieContainer = new CookieContainer();            var response = request.GetResponse();            response.Close();            CookieContainer = container;        }        public CookieAwareWebClient(CookieContainer container)        {            CookieContainer = container;        }        public CookieAwareWebClient()            : this(new CookieContainer())        { }        public CookieContainer CookieContainer { get; private set; }        protected override WebRequest GetWebRequest(Uri address)        {            var request = (HttpWebRequest)base.GetWebRequest(address);            request.CookieContainer = CookieContainer;            return request;        }    }

All webpageString would return is the gta4-mods.com page when you are not logged in.

 

What am I doing wrong? Am I using the wrong webpage, or is there something else I messed up? Thanks

 

Oh and sorry that this really isn't a scripting problem, I didn't know where to post this lol

Edited by LetsPlayOrDy

Share this post


Link to post
Share on other sites
AgentWD40

perhaps you need to use "UploadValues"

 

http://www.imvumafias.org/community/viewtopic.php?f=109&t=8497

public class CookieAwareWebClient : WebClient{    private readonly CookieContainer _cookie = new CookieContainer();    protected override WebRequest GetWebRequest(Uri address)    {        WebRequest request = base.GetWebRequest(address);        if (request is HttpWebRequest)        {            (request as HttpWebRequest).CookieContainer = _cookie;        }        return request;    }}public class SignIn : Script{    SignIn()    {        var cCookie = new CookieAwareWebClient();        var loginData = new NameValueCollection { { "avatarname", "IMVU Username" }, { "password", "IMVU Password" } };        cCookie.UploadValues("https://secure.imvu.com/login/login/", "POST", loginData);    }}

http://www.codeproject.com/Articles/624624/Using-a-Cookie-Aware-WebClient-to-Persist-Authenti

 

 

 

//Create an instance of your new CookieAware Web Clientusing (var client = new CookieAwareWebClient()){   //Authenticate (username and password can be either hard-coded or pulled from a settings area)   var values = new NameValueCollection{{ "UserName", username },{ "Password", password }};   //Perform authentication - after this has been performed   //the cookie will be stored within the Web Client   client.UploadValues(new Uri("http://www.yourdomain.com/Account/LogOn/"), "POST", values);   //Authentication worked! Access the secure area (you can use a   //variety of methods here such as UploadFile, UploadValues, etc.)   client.UploadString(new Uri("http://www.yourdomain.com/Secure/YourSecureMethod"),      "POST", "Example Message");           }

 

 

Edited by hardsty1e

Share this post


Link to post
Share on other sites
Jitnaught

Nope, that doesn't work either. If nobody knows of any way that's fine, I'll just use a WebBrowser in my app for the user to sign in to. I just wanted to know if it was possible this way before I used a WebBrowser.

Share this post


Link to post
Share on other sites
AgentWD40

Nope, that doesn't work either. If nobody knows of any way that's fine, I'll just use a WebBrowser in my app for the user to sign in to. I just wanted to know if it was possible this way before I used a WebBrowser.

found this recently

http://vbcity.com/blogs/jatkinson/archive/2009/12/12/programmatically-entering-and-data-using-the-webbrowser-control.aspx

Share this post


Link to post
Share on other sites
leftas

Instead of "username" and password you need to use "vb_login_username" and "vb_login_password", next time look what data is firefox/chrome is sending to webpage as I do in firefox(firebug, or inspect and then network)

V5Mt8hz.png

All best,

Paul.

Share this post


Link to post
Share on other sites
Jitnaught

I've tried that too, didn't work (for me at least).

Share this post


Link to post
Share on other sites
byteMe420

use httpwebrequest and set it up as a post method include the post parameters that leftas is showing you... if you do it right it works... httpwebrequest is what u should use.

Edited by byteMe420

Share this post


Link to post
Share on other sites
byteMe420

I've tried that too, didn't work (for me at least).

what did you try? paste your code because the code you posted in your first post obviously is different than the post parameters shown when using a browser.

Share this post


Link to post
Share on other sites
Jitnaught

I think it's pretty self explanatory if you looked at what I replied to.

Share this post


Link to post
Share on other sites
rappo

vBulletin is configured to only allow POST requests from certain domains, so this isn't going to work even if you've got the code all right... I'd suggest a web view :)

Share this post


Link to post
Share on other sites
Jitnaught

vBulletin is configured to only allow POST requests from certain domains, so this isn't going to work even if you've got the code all right... I'd suggest a web view :)

Thanks for the tip :)

Share this post


Link to post
Share on other sites
NTAuthority

vBulletin is configured to only allow POST requests from certain domains, so this isn't going to work even if you've got the code all right... I'd suggest a web view :)

... then set a Referer header? it's not as if 'certain domains' is enforceable in any way

Share this post


Link to post
Share on other sites
leftas

Googling helps! :)

http://stackoverflow.com/questions/18745522/how-to-login-to-a-vbulletin-forum-and-get-user-group-id-in-c-sharp-application

1 minute searching.

http://forum.codecall.net/topic/53896-c-vbulletin-login-function/

It returns the cookie data so when loading other pages of the site, you can just send the cookies and stay logged in with the headers.add("cookie", cookie) method.

 

All the best,

Paul.

Edited by leftas

Share this post


Link to post
Share on other sites
byteMe420

vBulletin is configured to only allow POST requests from certain domains, so this isn't going to work even if you've got the code all right... I'd suggest a web view :)

if a browser can do it then so can httpwebrequest

Edited by byteMe420

Share this post


Link to post
Share on other sites
byteMe420

I think it's pretty self explanatory if you looked at what I replied to.

 

your code is wrong, you arent even using the correct post parameters

 

 

vBulletin is configured to only allow POST requests from certain domains, so this isn't going to work even if you've got the code all right... I'd suggest a web view :)

Thanks for the tip :)

 

dont listen to him, he is clueless

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • 1 User Currently Viewing
    0 Members, 0 Anonymous, 1 Guest

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.