简体   繁体   中英

Passing [] in HttpRequestMessage query parameter

I'm trying to pass a query parameter to a REST API. The parameter has [] characters in it, and I just cannot get it to work.

This is my code:

var request = new HttpRequestMessage();

request.RequestUri = new Uri("https://api.eu.itglue.com/organizations");
request.Method = HttpMethod.Get;

This works, but this doesn't:

var request = new HttpRequestMessage();

request.RequestUri = new Uri("https://api.eu.itglue.com/organizations?page[size]=1000");
request.Method = HttpMethod.Get;

What am I missing?

Thanks!

I believe square brackets have limitations in their URL usage, and you need to encode them to %5B and %5D, respectively. Like this:

request.RequestUri = new Uri("https://api.eu.itglue.com/organizations?page%5Bsize%5D=1000");

More Info: Are square brackets permitted in URLs?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM