I am working on side-project using ASP.Net Core web api. I am currently using Postman so I can interact with custom middleware. As you can see in the picture I have a User id and would like the request header to have more than one value for the user id key. Everytime I debug the api, the request header only counts one value instead of two values. I have looked at the Postman help page but it doesn't really cover any material regarding my issue. So to condense my question, is there a way in Postman that a key (For my scenario, User Id) can hold more than one value.
-
1Please post your code for your endpoint. We have no idea what type user id is.Hayden– Hayden2021-08-25 04:41:44 +00:00Commented Aug 25, 2021 at 4:41
-
No, you can only send String in Header Param, JSON is only a one option to send multiple values but there is no way to send JSON or any thing else apart from string in request header.Ravi S.– Ravi S.2021-08-25 04:43:18 +00:00Commented Aug 25, 2021 at 4:43
-
@RaviS. ok thank you for clearing that up.NickDotCore– NickDotCore2021-08-25 05:06:15 +00:00Commented Aug 25, 2021 at 5:06
-
1@RaviS that makes no sense: "you can't send JSON in a request header, you can only send a string" - what you do you think JSON is?Caius Jard– Caius Jard2021-08-25 06:13:55 +00:00Commented Aug 25, 2021 at 6:13
-
@CaiusJard I already know JSON is also a String type, and JSON is data interchange format.Ravi S.– Ravi S.2021-08-26 08:12:18 +00:00Commented Aug 26, 2021 at 8:12
2 Answers
Your question doesn't really make sense. Postman will send the data you put, to the server. The data you put is "1,2". At the server end, if you pull the userId value and split it on the comma, you have your two values, no?
I find it incredibly unlikely that when you pull userId at the server, the value of the header is "1" and the other id has disappeared. If the web did that loads of headers (such as your gzip, deflate, br there) would get lost and stuff wouldn't work properly
Comments
In java with spring boot framework i have idea about it we have to send List userIds from request controller method this method you have to take as post method and send that data into body part with
@PostMapping("/listUsers")
public String getList(@RequestBody List<Integer> userIds) {
// call service method
return "page";
}
Json Request from postman
{
1,2,3,4,5............
}
In dot net core
[Produces("application/json")]
[Route("api/accounts")]
public class AccountsController : Controller
{
[HttpGet]
[Route("servicesbycategoryids")]
public IActionResult ServicesByCategoryIds([FromQuery] int[] ids)
{
return Ok();
}
}
