I am new in python. I wanna build a bot in c#. Can i use this "urllib2" in dot net or is there any alternative in dot net? please help...
Consider using HttpRequest and/or WebClient. Or, you may need to use sockets. It depends on what kind of bot you want to build.
Also, there is a python implementation for .NET called IronPython. This is able to use standard python libraries and the .NET framework as well.
On a side note I'd recommend you to choose the right language/framework after you found out what you want to do and observed the alternatives, not before that.
Most of the equivalent functionality is in System.Web namespace:
The System.Web namespace supplies classes and interfaces that enable browser-server communication. This namespace includes the HttpRequest class, which provides extensive information about the current HTTP request; the HttpResponse class, which manages HTTP output to the client; and the HttpServerUtility class, which provides access to server-side utilities and processes. System.Web also includes classes for cookie manipulation, file transfer, exception information, and output cache control.
A close cousin of urlopen
is the System.Net.Webclient class:
Provides common methods for sending data to and receiving data from a resource identified by a URI.
using System;
using System.Net;
using System.IO;
public class Test
{
public static void Main (string[] args)
{
if (args == null || args.Length == 0)
{
throw new ApplicationException ("Specify the URI of the resource to retrieve.");
}
WebClient client = new WebClient ();
// Add a user agent header in case the
// requested URI contains a query.
client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Stream data = client.OpenRead (args[0]);
StreamReader reader = new StreamReader (data);
string s = reader.ReadToEnd ();
Console.WriteLine (s);
data.Close ();
reader.Close ();
}
}