Joke Collection Website - Blessing messages - How to use C# call interface to log in and send short messages?

How to use C# call interface to log in and send short messages?

Private? Static electricity Read only? String? DefaultUserAgent? =? “Mozilla/4.0? (compatible; ? MSIE? 6.0; ? Windows? NT? 5.2; ? SV 1; ? . Net? CLR? 1. 1.4322; ? . Net? CLR? 2.0.50727)";

///? & lt summary & gt?

///? Create HTTP requests in POST mode?

///? & lt/summary & gt; ?

///? & ltparam? Name = "url"> URL requested.

///? & ltparam? Name = "parameters"> Dictionary of parameter names and parameter values published with the request.

///? & ltparam? Name = "timeout"> timeout requested.

///? & ltparam? Name = "userAgent"> Client browser information requested; can be empty.

///? & ltparam? Name = "requestEncoding"> the encoding used when sending HTTP requests.

///? & ltparam? Name = "Cookies"> If authentication is not required, the cookie information sent by HTTP request can be empty.

///? & ltreturns & gt& lt/returns & gt; ?

Public? Static electricity String? PostHttpResponse (string? Website,? Dictionary & lt string,? String & gt? Parameters,

int? Timeout)

{

attempt

{

What if? (string. IsNullOrEmpty(url))

{

Throw? New? ArgumentNullException(" URL ");

}

HttpWebRequest? Request? =? Network request. Create (URL)? As? HttpWebRequest

Request. Service point. expect 100 continue? =? Fake;

Request. ServicePoint.UseNagleAlgorithm? =? Fake; ? //Do you use it? Nagel? Don't use it increase efficiency

//request. AllowWriteStreamBuffering? =? Fake; ? //Is the data buffered? Fake? increase efficiency

Request. Method? =? "post";

Request. ContentType? =? ”application/x-www-form-urlencoded”;

Request. UserAgent? =? DefaultUserAgent

What if? (Timeout. Hash value)

{

Request. Timeout? =? Timeout. Value;

}

other

{

Request. Timeout? =? 20000;

}

Coding? requestEncoding? =? Coding. get encoding(" UTF-8 ");

//If POST data is needed?

What if? (! (parameters? ==? null? ||? Parameters. Count? ==? 0))

{

StringBuilder? Buffer? =? New? StringBuilder();

int? Me? =? 0;

foreach? (string? Keys? Are you online? Parameters. Keys)

{

What if? (me? & gt? 0)

{

Buffer. append format(& amp; {0}={ 1}",? The key? parameters[key]);

}

other

{

Buffer. AppendFormat("{0}={ 1} ",? The key? parameters[key]);

}

i++;

}

byte[]? Data? =? Request coding. GetBytes (buffer. ToString());

Use? (flow? Stream? =? Request. GetRequestStream())

{

Stream. Write (data,? 0,? Data. Length);

}

}

//Get the response and set the response code.

HttpWebResponse? Response? =? (HttpWebResponse) request. GetResponse();

String? Coding? =? Response. ContentEncoding

What if? (code? ==? null? ||? Coding. Length? & lt? 1)

{

Coding? =? “UTF-8”; ? //Default encoding

}

//Read the response stream

StreamReader? Readers? =? New? StreamReader (response. GetResponseStream(),? Coding. GetEncoding);

String? returnData? =? Readers. ReadToEnd();

Readers. dispose();

Response. close();

Return? returnData

}

Catch? (exception? ex)

{

MessageUtil。 ShowWarning (e.g. message);

}

Return? "";

} the method of requesting the interface

Dictionary & lt string,? String & gt? Parameters? =? New? Dictionary & lt string,? String & gt ();

Parameters. Add("USER_ACCOUNT ",user name);

Parameters. Add("USER_PASSWORD ",pwd);

Return? Httpposthelper。 Posthttpresponse ("interface URL",? Parameters? null);