Is this Possible that write a Socket by C# in ASP.net ? for Example Can i write a Code Like this Perl Code in C# and asp.net ? :
> use HTTP::Request::Common qw(POST);
> use LWP::UserAgent; $ua = new
> LWP::UserAgent(agent => 'Mozilla/5.0(Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5)Gecko/20060719 Firefox/1.5.0.5');
> $ua -> timeout(20);
> my $req = POST 'http://Example.com/',
> [ login_username => 'mehdi' , login22 => '654321' , go => 'submit'];
> my $content = $ua-&开发者_Python百科gt;request($req);
please Give me an example or Convert the above code to C# and asp.net . Thanks in Advance .
Yes, you could achieve the same functionality in .NET using the WebClient class:
class Program
{
static void Main()
{
using (var client = new WebClient())
{
client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0(Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5)Gecko/20060719 Firefox/1.5.0.5";
var values = new NameValueCollection
{
{ "login_username", "mehdi" },
{ "login22", "654321" },
{ "go", "submit" }
};
var result = client.UploadValues("http://example.com", values);
// TODO: handle the result here like
Console.WriteLine(Encoding.Default.GetString(result));
}
}
}
精彩评论