是否有一个HttpWebRequest的一个HTTP参数值的大小限制? [英] Is there a limit on the size of a http argument value in a HttpWebRequest?

查看:1837
本文介绍了是否有一个HttpWebRequest的一个HTTP参数值的大小限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试了几个不同的公共REST风格的API在HTTP参数值的名称各不同,但在概念上所有的工作类似。但是没有一家公司的连接,所以它肯定的东西我的结束。

I am testing out a few different public RESTful APIs each differing in http argument value name, but in concept all work similarly. However none of the companies are connected so it must be something on my end.

在.NET中,我得到试图获得HttpWebResponse如果出现以下错误:

Within .NET I get the following error when trying to obtain the HttpWebResponse:

消息:服务器提交了协议冲突节= ResponseStatusLine
状态:ServerProtocolViolation {11}

Message: "The server committed a protocol violation. Section=ResponseStatusLine"
Status: ServerProtocolViolation {11}

使用招,我发现这头回来是不存在的,这是问题的原因(甚至没有present和格式不正确):

Using Fiddler, I am finding that the headers coming back are non-existent and this is the cause of the issue (not even present and improperly formatted):

HTTP / 1.0 200这车服务器未返回头

我派中的参数是一个冗长的文字新闻文章。我已经剥离所有 puntuation,人物等的只是的,以确保没有广域网interferring。我用一个StringBuilder,然后创建像下面的URI建文指出:

The parameter I am sending in is a lengthy text news article. I have stripped ALL puntuation, characters, etc just to make sure nothing wans interferring. I build the text out using a StringBuilder and then create the URI like below:

Dim sb As New StringBuilder
sb.Append("&apiKey=" + HttpUtility.UrlEncode("123456789"))
sb.Append("&inputText=" + HttpUtility.UrlEncode(Me.MyTestText))
Dim ApiHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(New Uri(BaseRequestURL + sb.ToString.Trim())), HttpWebRequest)
Dim ApiHttpWebResponse As HttpWebResponse = CType(ApiHttpWebRequest.GetResponse(), HttpWebResponse)

这code DOES 工作,大多数文本我送它。有趣的事情,我发现是,如果我缩短我发送文本,然后它的作品!我想不通的完全的的threashold或突破点。该stringbuilders值扩大HttpUtility.UrlEn code函数运行后反对。然而,在尺寸文字的大小,远远低于规定被作为布局在MSDN的的通过,任何的的HttpWebRequest的的.config设置任何尺寸的限制仅约5-8千字节我使用的API(例如1限额为150千字节的文本)。我甚至尝试设置所有这些值,以-1,在web.config中,这意味着:。值为-1表示没有大小限制将在响应头的罚款

This code DOES work with most text I send it. The interesting thing I am finding is that if I shorten the text I am sending then it works! I can't figure out exactly the threashold or breaking point. The stringbuilders values expand after the HttpUtility.UrlEncode function is run against it. However the text in size is only about 5-8 kilobytes in size and well below any size limitations set forth by the 'httpWebRequest' .config settings as laid out in the MSDN or by that of any of the APIs I am using (for example 1 limit is 150 kilobytes of text). I even tried setting all of those values to "-1" in the web.config which means: "A value of -1 indicates that no size limit will be imposed on the response headers."

有没有对HTTP参数值的大小,或其他任何东西在这里,我很想念,将导致此限制?谢谢!

Is there a limit on the size of the http argument value or anything else here I am missing that would cause this? Thanks!

推荐答案

以及典型的,当我张贴的问题时,的问题的被吓坏了,和presents的解决方案;)

Well as typical when I post a question, the problem gets scared, and presents the solution ;)

感谢您为previous联系,但因为我不是在浏览器中执行此操作直接,这些限制都没有问题,我的情况。

Thank you for the previous link, but since I wasn't doing this directly in a browser, those limitations were not the issue in my case.

我使用HttpWebRequest的defualt'方法'值是GET,我应该用POST的几个原因,其中包括请求发出的征服长度。因此增加的code的以下行后的创建Request对象,解决了该问题的:

I was using the HttpWebRequest's defualt 'Method' value which is "GET" and I should be using "POST" for a few reasons, including the conquering the length of the request issue. So adding the following line of code after creation of the Request object, fixed the issue:

ApiHttpWebRequest.Method = "POST"

这个链接(旧,但内容仍持有)也是有帮助的:

This link (old but content still holds) was also helpful:

什么是查询字符串极限/ GET / URL参数:
http://classicasp.aspfaq.com/forms/what-is-the-limit-on-querystring/get/url-parameters.html

...和的TechNet一个很好的说明:

...and a good description from TechNet:

GET方法,这是在前面的示例中使用,追加名称/值对的URL。不幸的是,一个URL的长度是有限的,所以这种方法只适用于如果只有几个参数的网址,如果形式使用了大量的参数,或如果参数包含大量数据可被截断。此外,在该URL传递参数可见,在browsernot的地址字段为一个密码,它的最佳位置显示。

的替代GET方法是POST方法。此方法包HTTP请求,这使得更清洁URL和强加的形式输出没有大小限制的体内的名称/值对。它也更安全。

这篇关于是否有一个HttpWebRequest的一个HTTP参数值的大小限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆