How i can pass 500 or even 1000 URL each time to c# webapi and return a result? should i use get method or post method?
Asked
Active
Viewed 1,331 times
2 Answers
1
You should post array of integer in body.
If you are using jquery to do the post, you can do something like below.
$.ajax({
type: "POST",
url: url,
data: [1, 2, 3]
});
In your Api -
public HttpResponse Post(int[] ids){}

Yousuf
- 3,105
- 7
- 28
- 38
-
the problem is length of params, as i mentioned the params are about 1000 URL and earch url is 100 character length, so easily exceeded the 2048 URL length limitation – SnowStorm Aug 13 '15 at 20:07
-
If you do a HttpPost it will not hit the url length limit. I think it is hitting the url max limit as you are passing parameters in the url to Http GET method – Yousuf Aug 13 '15 at 20:18
-
but if HttpPost used, how the results(in this case array of URLs) is returned? – SnowStorm Aug 14 '15 at 04:46
-
Instead of returning HttpResponse, you can return list. you can return list type from a post method. – Yousuf Aug 14 '15 at 14:09
0
First step How to pass an array of integers to ASP.NET Web API?
You need a post method in your controller. And receive an array of strings.
public IEnumerable<Category> GetCategories([FromUri] int[] categoryIds)
and send request
/Categories?categoryids=1&categoryids=2&categoryids=3
Then in your method do the calculations and return a result as usual

Community
- 1
- 1

Juan Carlos Oropeza
- 47,252
- 12
- 78
- 118
-
I need to pass about 1000 URL and each URL length is about 100 character, thus total webapi params length reach about 100,000 character that is more than standard URL length – SnowStorm Aug 13 '15 at 19:54
-
Is just an example, you can also pass an object to your api as string[] using Jquey AJAX function. – Juan Carlos Oropeza Aug 13 '15 at 20:06
-
the problem is length of params, as i mentioned the params are about 1000 URL and earch url is 100 character length, so easily exceeded the 2048 URL length limitation – SnowStorm Aug 13 '15 at 20:09