如何以json格式发布非常大的请求数据作为查询字符串参数? [英] How to post very large request data as querystring parameter in json format ?

查看:76
本文介绍了如何以json格式发布非常大的请求数据作为查询字符串参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,我需要在JSON数据中发布大数据作为请求的一部分。

我已经采用了一种方法,该方法将请求数据作为值的查询字符串参数。



当请求数据值长度较小时,此工作,但在请求数据长度大幅增加时不起作用。我已经尝试在web.config中增加maxQueryStringLength和maxRequest Length但仍然无法发布。以下错误显示为无效请求。







请帮忙。



预付款



我尝试过:



注意:请求已由外部网站发布到Web api控制器操作方法。这适用于本地但不适用于实时服务器。在web.config中尝试了所有可能的配置设置,但我仍然无法发布请求数据。

解决方案

POST请求的第一条规则。不要F * ck的URL! URL和查询字符串仅用于获取数据。当您发出HTTP GET请求时,请使用查询字符串或URL路由等来获取数据,将过滤添加到内容中。但是当您要发布数据时,请始终使用请求正文,这也是您在登录时看不到密码字段附加到URL的原因之一,该数据应该包含(或在)标题中或者在请求体中作为单独的对象。请求正文非常适合包含要随请求传递的数据,然后您可以稍后访问该数据。



如需更多要求,请阅读 html - http请求正文是什么意思? - Stack Overflow [ ^ ]。

引用:

在web.config中尝试了所有可能的配置设置,但仍然我无法发布请求数据。

最后,一组优秀的服务器管理员阻止写入API消耗不佳。听取我的建议,删除该查询字符串,并开始接受数据作为标题,就像从任何标题访问数据一样,否则使用正文并添加 [FromBody] 属性。在本地,您可以修改服务器的良好实践,并考虑不好的实践。



ASP.NET Web API中的参数绑定| ASP.NET站点 [ ^ ]



另外,URL大小本身有限制; 2000个字符。在这里阅读更多相关信息, http - 什么是不同浏览器中URL的最大长度? - 堆栈溢出 [ ^ ]。这可能是您的请求每次都无效的原因。



*抱歉,这是我读到这个问题时第一个出现在我面前的表情。


I have one requirement where i need to post large data as part of request in JSON data.
I have followed an approach that will take an query string parameter with request data as value.

This work when request data value length is small, but do not work when request data length increases largely. I have tried increasing maxQueryStringLength and also maxRequest Length in web.config but still am unable to do post that.The following error is been shown as "Invalid Request".



Please help.

Advance thanks

What I have tried:

Note:Request is been posted to an web api controller action method by an external site. This works in local but not in live servers. All possible configuration settings tried in web.config, but still i am unable to post the request data.

解决方案

First rule of POST requests. Do not F*ck the URLs! URLs and query strings are only used to GET the data. When you are issuing an HTTP GET request, use Query Strings or URL routings etc. to get the data, add the filtering to the content. But when you are going to post the data, always use the request body and that is one of the reasons why you do not see a password field being appended to the URL when you log in, that data should be with (or in) headers or in the request body as a separate object. The request body is well suited for containing the data to be passed with the request, and then you can later access that data.

For more on request body, please read, html - What does it mean http request body? - Stack Overflow[^].

Quote:

All possible configuration settings tried in web.config, but still i am unable to post the request data.

Finally, a good group of server admins who are blocking poorly written API consumption. Take my advice, remove that query string, and start to accept the data as either a header as you would access data from any header, otherwise use the body and add the [FromBody] attribute. Locally, you can tinker the server's good practices, and consider the bad ones.

Parameter Binding in ASP.NET Web API | The ASP.NET Site[^]

Plus, there is a limit on the URL size itself; 2000 characters. Read more about it here, http - What is the maximum length of a URL in different browsers? - Stack Overflow[^]. This might be reason why your request is being invalid every time.

* Sorry, but this was the first expression that came to me when I read the question.


这篇关于如何以json格式发布非常大的请求数据作为查询字符串参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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