Click here to Skip to main content
15,917,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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.
Posted
Updated 25-Jan-17 9:47am
Comments
Ayodeji Oluwatomiwo 25-Jan-17 9:28am    
Let's see what you've tried. **the exact point where you are passing the data into the query string
F-ES Sitecore 25-Jan-17 9:50am    
The querystring is not for passing a lot of data, if you need to pass a lot of data to a POST instead.
Anilkumar2vvv 27-Jan-17 2:34am    
using post only but it is not working
F-ES Sitecore 27-Jan-17 4:08am    
Then I guess there is a problem with your code.
Patrice T 25-Jan-17 15:24pm    
Define "increases largely"

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900