Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi All,

I am a .Net expert and don't know much details about Python (Used python.Net long back).

I came across below script from http://www.kunaldua.com/blog/2009/12/reliance-wireless-broadband-auto-login-script/[^] site.

I would like to convert below code to C#, so I can create a small and handy application in C# for my parent.

C#
import urllib2, urllib, cookielib

username = '1111111111111111' #replace the text within quotes with your username
password = 'password'   #replace the text within quotes with your password

jar = cookielib.FileCookieJar("cookies")
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))

response = opener.open("http://10.239.89.15/reliance/startportal_isg.do")

login_data = urllib.urlencode({'userId' : username, 'password' : password, 'action' : 'doLoginSubmit'})
resp = opene


Thank you for your help....

Thanks
Rushikesh Joshi
Posted
Updated 16-Jul-23 1:24am
Comments
Sergey Alexandrovich Kryukov 6-Jul-12 14:22pm    
If you are a .NET expert, you don't need to translate anything, especially this short. You only need to know what do you want. Do you? :-)
--SA
bbirajdar 8-Jul-12 14:08pm    
Go ahead and convert it..

1 solution

use www.codeconvert.ai/app[^]

C#
using System;
using System.Net;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string username = "1111111111111111";
        string password = "password";
        CookieContainer jar = new CookieContainer();
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.239.89.15/reliance/startportal_isg.do");
        request.CookieContainer = jar;
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        string responseText = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();
        string loginData = $"userId={username}&password={password}&action=doLoginSubmit";
        byte[] dataBytes = System.Text.Encoding.UTF8.GetBytes(loginData);
        request = (HttpWebRequest)WebRequest.Create("http://10.239.89.15/reliance/startportal_isg.do");
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = dataBytes.Length;
        request.CookieContainer = jar;
        System.IO.Stream requestBody = request.GetRequestStream();
        requestBody.Write(dataBytes, 0, dataBytes.Length);
        requestBody.Close();
        response = (HttpWebResponse)request.GetResponse();
        responseText = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();
    }
}
 
Share this answer
 
v2
Comments
Graeme_Grant 16-Jul-23 10:50am    
The question is 11+ years old ... maybe focus on more current questions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900