C# - 使用WebRequest发布大型内容或字符串

时间:2017-02-23 17:59:22

标签: c#

我正在尝试发布大量内容,大约13000个字符。但我一直在进行手术。更改超时没有用,因为它需要很长时间。 这是我的代码

string textToSpin = rtbOri.Text; //13000 Characters

            string post_data = "api_key=" + api_key + "&article=" + HttpUtility.UrlEncode(textToSpin) + "&lang=" + lang;

            HttpWebRequest request = (HttpWebRequest)
            WebRequest.Create(serviceUri);
            request.Credentials = new NetworkCredential("userName", "password");
            request.Method = "POST";
            request.Timeout = Timeout.Infinite;
            byte[] postBytes = Encoding.ASCII.GetBytes(post_data);

            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = postBytes.Length;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(postBytes, 0, postBytes.Length);
            requestStream.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string reader = new StreamReader(response.GetResponseStream()).ReadToEnd();
            rtbSpin.AppendText(reader);

有什么想法吗?感谢

0 个答案:

没有答案