HttpWebRequest:请求已中止:请求已取消

发布于 2024-09-28 04:20:07 字数 986 浏览 1 评论 0原文

我正在尝试发送 xml 文件并返回 xml 文件作为响应。我尝试发送的文件略多于 20,000 KB。我尝试添加超时,并将 keepalive 设置为 false,但都不起作用。我四处搜寻,但找不到任何适合我的东西。截至目前,我刚刚将文件分解并以 3 - 4 千 kb 之间的文件形式发送。如果有人有任何想法,我将非常感激。谢谢。

HttpWebRequest hrequest = (HttpWebRequest)WebRequest.Create();
hrequest.KeepAlive = false;
hrequest.Timeout = 10000 * 60;
hrequest.Method = "POST";
hrequest.Headers.Add("Authorization", "Basic " + 
    Convert.ToBase64String(Encoding.ASCII.GetBytes("")));
hrequest.ContentType = "application/x-www-form-urlencoded";
Byte[] byteArray = Encoding.UTF8.GetBytes(
    File.ReadAllText("C:\\Payvment\\UploadProductsXML\\" + qStart + ".xml"));
hrequest.ContentLength = byteArray.Length;
Stream reqStream = hrequest.GetRequestStream();
reqStream.Write(byteArray, 0, byteArray.Length);
reqStream.Close();
StreamReader streamRdr = new StreamReader(
    hrequest.GetResponse().GetResponseStream());
string strResponse = streamRdr.ReadToEnd();
StringReader stringRdr = new StringReader(strResponse);

I am trying to send up an xml file and get back an xml file as a response. The file I am trying to send up is slightly over 20,000 KB. I tried adding a timeout, and setting keepalive to false, but neither one works. I've searched around but I can't find anything that is applicable to me. As of now I've just broken the file down and have been sending it up in files between 3 - 4 thousand kb. if anyone has any ideas I would really appreciate it. Thanx.

HttpWebRequest hrequest = (HttpWebRequest)WebRequest.Create();
hrequest.KeepAlive = false;
hrequest.Timeout = 10000 * 60;
hrequest.Method = "POST";
hrequest.Headers.Add("Authorization", "Basic " + 
    Convert.ToBase64String(Encoding.ASCII.GetBytes("")));
hrequest.ContentType = "application/x-www-form-urlencoded";
Byte[] byteArray = Encoding.UTF8.GetBytes(
    File.ReadAllText("C:\\Payvment\\UploadProductsXML\\" + qStart + ".xml"));
hrequest.ContentLength = byteArray.Length;
Stream reqStream = hrequest.GetRequestStream();
reqStream.Write(byteArray, 0, byteArray.Length);
reqStream.Close();
StreamReader streamRdr = new StreamReader(
    hrequest.GetResponse().GetResponseStream());
string strResponse = streamRdr.ReadToEnd();
StringReader stringRdr = new StringReader(strResponse);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飞烟轻若梦 2024-10-05 04:20:07

Web 服务器肯定不会允许这么大的请求,除非您更改消息大小最大值。在 wcf 中,属性为 maxRecievedMessageSize,默认为 64k。另外,其中一些属性,最大大小/超时是服务器上的属性,修改您的请求不会改变它的想法。

the web server definitely won't allow a request that large unless you change the message size max. in wcf the property is maxRecievedMessageSize and defaults to 64k. also, some of these properties, max size/timeout are properties on the server, and modifying your request is not going to change its mind.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文