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?
///? & 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);
- Related articles
- What should my girlfriend say if she wants to shoot a birthday video and say her best wishes?
- How to intercept Lenovo mobile phone s939 WeChat to others?
- Complete works of short wedding greetings
- Hello: I was cheated by the postal savings credit card customer service today! I received 20 18 coins from them, 2969 yuan. What should I do?
- In the debate, we lied about honesty and goodwill. I'm against the positive. Are we anxious about the fatal weakness of the positive? ! !
- News details
- Is the lightning treasure POS machine safe to use? Will personal information be leaked?
- Do Nantong transfer workers make phone calls in the early hours of the morning?
- What does it mean for Changsha Bank to make an appointment to pick up the number and display it to the number?
- How to restore the iPhone information icon to the desktop