Csharp: HttpWebRequest and HttpWebResponse, httpwebresponse
Http://stackoverflow.com/questions/4015324/http-request-with-post
Response. charset = "GBK"; // GBK // gb2312 this. codePage = 936; Session. codePage = 936; Encoding myEncoding = Encoding. getEncoding ("GBK"); byte [] data = System. text. encoding. getEncoding ("GBK "). getBytes ("907953"); // System. text. unicodeEncoding. ASCII. getBytes ("135246"); // UTF8 Base64Encoder myEncoder = new Base64Encoder (data); StringBuilder sb = new StringBuilder (); sb. append (myEncoder. getEncoded (); string content = HttpUtility. urlEncode ("juwen: three additional hours required: 2014-07-12: 15: 58, csharp", myEncoding); String sResult =" http://www2.lansea.com.cn/servlet/UserServiceAPI?method=sendSMS&isLongSms=0&username=87&password=232&smstype=0&mobile=13824350518&content= "+ Content +" "; // string param = HttpUtility. urlEncode (sResult, myEncoding); Response. write (sResult); byte [] postBytes = Encoding. getEncoding ("GBK "). getBytes (sResult); // Encoding. getEncoding ("GBK "). getBytes (sResult); try {HttpWebRequest req = (HttpWebRequest) HttpWebRequest. create (sResult); // sResult req. method = "POST"; req. contentType = "application/x-www-form-urlencoded; charset = GBK"; req. headers ["Accept-Charset"] = "GBK"; req. headers ["Accept-Language"] = "zh-CN, zh; q = 0. "; req. allowAutoRedirect = false; req. contentLength = postBytes. length; Stream webStream = req. getRequestStream (); // send data webStream. write (postBytes, 0, postBytes. length); webStream. close (); // get the returned data HttpWebResponse webResponse = (HttpWebResponse) req. getResponse (); StreamReader reader = new StreamReader (webResponse. getResponseStream (), Encoding. getEncoding ("GBK"); sResult = reader. readToEnd (); sResult. trim (); this. textBox1.Text = sResult; // returns whether the message is successfully sent.} catch (Exception ex) {ex. message. toString (); // sResult = ""; // return sResult ;}
C # HttpWebRequest continuous post
Hreq. Timeout = 2000;
The main reason for adding the above Code is that the default request timeout time is 100 seconds. when too many requests are opened and the main thread is blocked, what you said will happen.
I put my code in The onclick event of a Button. It can be normally displayed as 10. No problem. Didn't you leave the code in the Form constructor?
C # winform uses httpwebrequest and httpwebresponse for response. The response speed is sometimes slow. I don't know why
Httpwebrequest ----> http protocol