1

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.

enter image description here

NickDotCore
  • 63
  • 2
  • 7
  • 1
    Please post your code for your endpoint. We have no idea what type user id is. – Hayden Aug 25 '21 at 04: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. Aug 25 '21 at 04:43
  • @RaviS. ok thank you for clearing that up. – NickDotCore Aug 25 '21 at 05: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 Aug 25 '21 at 06:13
  • @CaiusJard I already know JSON is also a String type, and JSON is data interchange format. – Ravi S. Aug 26 '21 at 08:12

2 Answers2

0

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

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
0

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();
    }
}
Rajesh Patel
  • 170
  • 1
  • 1
  • 13
  • this isn't a java related issue, but I now know that header can't send json – NickDotCore Aug 25 '21 at 07:28
  • I know that this is solution of java, you have to send that data from body not from header in postman. if you want to pass list of data then you have to use POST method – Rajesh Patel Aug 25 '21 at 07:40
  • this is the link which are help to you:- https://stackoverflow.com/questions/51300861/passing-an-array-to-a-asp-net-core-web-api-action-method-httpget – Rajesh Patel Aug 25 '21 at 07:59
  • NickDotCore *I now know that header can't send json* - that's absolutely untrue and Ravi should not have misled you thus. Rajesh is doing the same, unfortunately. There is absolutely nothing stopping you putting JSON into an HTTP header, then pulling it out at the server end and deserializing it – Caius Jard Aug 26 '21 at 16:02