[C#] Imvu Login Code - Source [Updated 4-28-2014]

DataMine
by DataMine · 13 posts
9 years ago in .Net (C#, VB, etc)
Posted 9 years ago · Author
This is c# code for logging into IMVU with your program. You can find the Vb.net equivalent here: https://www.imvumafias.org/community/viewtop ... 109&t=8487

Note: This code now needs .Net 4.6 to work with IMVU's SSL update.

Code
string s = "POSTDATA=sauce=&avatarname=" + UserName + "&password=" + Password + "&password_strength=strong&sendto=";
CookieContainer cookieContainer = new CookieContainer();
byte[] bytes = new UTF8Encoding().GetBytes(s);
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://secure.imvu.com/login/login/");
httpWebRequest.Method = "POST";
httpWebRequest.KeepAlive = true;
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Referer = "http:www.imvu.com/login/";
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1";
httpWebRequest.ContentLength = (long)bytes.Length;
httpWebRequest.AllowAutoRedirect = false;

try
{
   using (Stream requestStream = httpWebRequest.GetRequestStream())
   {
      requestStream.Write(bytes, 0, bytes.Length);

      using (WebResponse response = httpWebRequest.GetResponse())
      {                       
         CookieCollection Cookies = ((HttpWebResponse)response).Cookies;
         
         //Check for a valid login cookie
         if (Cookies != null || Cookies["_imvu_avnm"] != null)
         {
            return true;
         }
      }

      return false;
   }
}
catch (WebException)
{
   return false;
}


This is the minimum amount of code you need to log into IMVU. If you want to make this really useful I recommend creating a CookieContainer property and storing the cookies from the login response so you can use it to make further calls to IMVU for data.
Posted 9 years ago
Thanks, needed this
Posted 8 years ago
D.M wrote:
This is c# code for logging into IMVU with your program. You can find the Vb.net equivalent here: https://www.imvumafias.org/community/viewtop ... 109&t=8487Login Cookie Declaration:
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)CookieContainer LoginCookie = new CookieContainer();GeSHi ©Sub Code:
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)string postData = "POSTDATA=sauce=&avatarname=" + UsernameBx.Text + "&" + "password=" + PasswordBx.Text;
UTF8Encoding encoding = new UTF8Encoding();
byte[] byteData = encoding.GetBytes(postData);HttpWebRequest postReq = (HttpWebRequest)WebRequest.Create("https://secure.imvu.com/login/login/");
postReq.Method = "POST";
postReq.CookieContainer = LoginCookie;
postReq.ContentType = "application/x-www-form-urlencoded";
postReq.ContentLength = byteData.Length;using (Stream postreqstream = postReq.GetRequestStream())
{postreqstream.Write(byteData, 0, byteData.Length);
}HttpWebResponse postresponse = (HttpWebResponse)postReq.GetResponse();
LoginCookie.Add(postresponse.Cookies);foreach (Cookie IMVUCookie in postresponse.Cookies)
{if (IMVUCookie != null){if (IMVUCookie.Name == "login_interstitial_seen"){//success}else{//failure}}
}
GeSHi ©The code above is my basic setup for logging into imvu with one of my tools. I do add more to it depending on the program I'm making such as error checking and disabling/enabling controls and changing control texts.


Works like a charm man. i managed to get it working and all. with my limited knowledge of c# atm. but i plan to add more stuff after login. when i can. appreciate the code btw bro. 8)
Posted 8 years ago
Wow, very interesting i'm gonna try it out as soon as possible this looks very cool hope it still works :badgrin:
Posted 6 years ago
Well , thank you for coding but it doesn't work because IMVU keeps it more secure.


im getting this error when run the code :

The underlying connection was closed: An unexpected error occurred on a send. :kat_emoji1:


i think we have the issue of using KeepAlive = false/true

Thanks.
Posted 6 years ago · Author
ZedMan wrote:
Well , thank you for coding but it doesn't work because IMVU keeps it more secure.


It works, you just have to be using .Net 4.6 which supports SSL.

@ZedMan
Posted 6 years ago
D.M wrote:
It works, you just have to be using .Net 4.6 which supports SSL.@ZedMan


oh right, i will update Framework, thanks DM
Posted 6 years ago · Author
Thanks to
@ZedMan
I was able to update the code in the original post with a much more reliable version.
Posted 2 years ago
Hi Gents,

I have used the code from DataMine to log (Which works :D) but cannot seem to get a simple api enquiry back to a room

if im do this on a web browser i get the api json stuff back perfectly
https://imvu.com/api/rooms/room_info.ph ... 48966-1020
if i log out of the web browser i get error room not available (something like that)

if i programatically access the above api in c# (wpf) it comes back error room not available. so thinking it needs cookie authentication tried that
and even after i sucessfully get the cookie container i issue the room api get and still room un-available
pulling my hair out here (2am in the morning and so frustrating )

there is various attempts in here nothing seems to work.........

This Json is haunting me lol when all i want to do is find out the room occupancy !!!!!
{"error":"Room does not exist","room_id":"156248966-1020"}


obviously user name and password i set as a working value for imvu and the authentication hits the break point debug = 1 ... and i tried a second attempt out side the authentication with a seperate html request which also comes back with the "does not exist"

Any Help would be greatly appriciated - Thank you in advance !!!!


Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net.Http;
using System.Net;
using System.IO;

namespace curl
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }


        static HttpClient client = new HttpClient();

        public string GetResponseFromURI(string httpinfo, CookieContainer mycookies)
        {
            Uri myUri = new Uri(httpinfo);
            var response = "";
            HttpResponseMessage result;

            var baseAddress = new Uri(httpinfo);
            // var cookieContainer = new CookieContainer();
            var cookieContainer = mycookies;
            using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
            using (var client = new HttpClient(handler) { BaseAddress = baseAddress })
            {
                // cookieContainer.Add(baseAddress, new Cookie("CookieName", "cookie_value"));
                Task task = Task.Run(async () =>
                {
                    result = await client.GetAsync(myUri);
                    if (result.IsSuccessStatusCode)
                    {
                        response = await result.Content.ReadAsStringAsync();
                    }
                });
                task.Wait();
            }
            return response;


        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            string myurl = "https://imvu.com/api/rooms/room_info.php?room_id=156248966-1020";

            string UserName = "zzzzzzzzzzzzzzzzzzzzzzz";
            string Password = "zzzzzzzzzzzzzzzzzzzzzzz";

            string s = "POSTDATA=sauce=&avatarname=" + UserName + "&password=" + Password + "&password_strength=strong&sendto=";
            CookieContainer cookieContainer = new CookieContainer();
            byte[] bytes = new UTF8Encoding().GetBytes(s);
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://secure.imvu.com/login/login/");
            httpWebRequest.Method = "POST";
            httpWebRequest.KeepAlive = true;
            httpWebRequest.CookieContainer = cookieContainer;
            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.Referer = "http:www.imvu.com/login/";
            httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1";
            httpWebRequest.ContentLength = (long)bytes.Length;
            httpWebRequest.AllowAutoRedirect = false;
            bool goodlogin = false;
            try
            {
                using (Stream requestStream = httpWebRequest.GetRequestStream())
                {
                    requestStream.Write(bytes, 0, bytes.Length);

                    using (WebResponse response = httpWebRequest.GetResponse())
                    {
                        CookieCollection Cookies = ((HttpWebResponse)response).Cookies;
                        //Check for a valid login cookie
                        if (Cookies != null || Cookies["_imvu_avnm"] != null)
                        {
                            cookieContainer.Add(Cookies);   //add the found cookie to the container
                            goodlogin = true;               // try it both ways .. try here using the same httpwebrequest but new url and json fetch

                            httpWebRequest = (HttpWebRequest)WebRequest.Create(myurl);
                            httpWebRequest.Method = "GET";
                            httpWebRequest.CookieContainer = cookieContainer;
                            httpWebRequest.ContentType = "application/json";
                            try
                            {
                                WebResponse response2 = httpWebRequest.GetResponse();
                                using (var reader = new StreamReader(response2.GetResponseStream()))
                                {
                                    var ApiStatus = reader.ReadToEnd();
                                    Console.WriteLine(ApiStatus);
                                    int debug = 1;
                                }

                            }
                            catch (WebException)
                            {
                                Console.WriteLine("Exception");
                            }

                        }
                    }
                }
            }
            catch (WebException)
            {
                Console.WriteLine("Exception");
            }

            if (goodlogin == true)
            {
                HttpWebRequest httpWebRequest2 = (HttpWebRequest)WebRequest.Create(myurl);
                httpWebRequest2.Method = "GET";
                // httpWebRequest2.KeepAlive = true;
                httpWebRequest2.CookieContainer = cookieContainer;
                httpWebRequest2.ContentType = "application/json";
                httpWebRequest2.Referer = "http:www.imvu.com/login/";
                httpWebRequest2.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1";
                //httpWebRequest2.ContentLength = (long)bytes.Length;
                httpWebRequest2.AllowAutoRedirect = false;
                try
                {
                    WebResponse response = httpWebRequest2.GetResponse();
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        var ApiStatus = reader.ReadToEnd();
                        int debug = 1;
                    }
                }
                catch (WebException)
                {
                    Console.WriteLine("Exception");
                }
            }
        }
    }
}

Create an account or sign in to comment

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

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

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

REGISTER A NEW ACCOUNT
Select a forum Protection     Help & Support     Introductions     Mafia News     IMVU News General Discussion     IMVU Lounge        IMVU Series / Roleplaying        Social Games     Mafia Market     Mafia Tools        Premium IMVU Tools        Off Topic Tools     Off Topic     Contests Creator Corner     Graphics Design        Photoshop        GIMP     Basic Creator Help     Catalog And Product Showcase     3D Meshing        3Ds Max        Sketchup        Blender Gangsters with Connections     White Hat Activities        Google Hacking        Trackers Programming Corner     Coding        Python        .Net (C#, VB, etc)        Flash        JAVA        Autoit        Batch        HTML & CSS        Javascript        PHP        Other        IMVU Homepage Codes           General           About me Panel           Messages Panel           Special Someone Panel           Visitors Panel           New Products Panel           Rankings Panel           Wishlist Panel           My Badges Panel           Outfits Panel           Url Panel           Groups Panel           Slideshow Panel           My Room Panel           Sandbox panel           Layouts     Help & Requests Free Credits     Approved Methods     Submit Methods Free Money     Approved Methods     Submit Methods Adult Corner     Get Mafia AP Here     AP Lounge        AP Social Games        Casual Dating Tips     IMVU Slave Market & Escorts