PortableRest icon indicating copy to clipboard operation
PortableRest copied to clipboard

AddQueryString generates invalid url

Open ghost opened this issue 10 years ago • 4 comments

Incorrectly Generates url as: "http://mydomain.com/v2/EndPointName/?&sample=12" Should be: "http://mydomain.com/v2/EndPointName/?sample=12"

var request = new RestRequest("EndPointName/"), System.Net.Http.HttpMethod.Post); request.AddQueryString("sample", 12);

var client = new RestClient(); client.BaseUrl = "http://mydomain.com/v2/"; // .. add some headers

RestResponse<MyModel> response = await client.SendAsync<MyModel>(request);

ghost avatar Aug 25 '14 04:08 ghost

Sorry for the delay in getting back to you. We generated the URL this way because it is still syntactically valid, and it cut down on the code required to generate the string. Is there a situation where it is causing the code to error out?

robertmclaws avatar Oct 09 '14 17:10 robertmclaws

Yes I have this problem too. It is apparently not necessarily syntactically correct to have the & right after the ?. I am getting response code 400 Invalid Request Parameter, and the reason is exactly that: the &.

It would be helpful to have this fixed, even if there is a bit of effort to generate the proper string.

brunck avatar Oct 31 '14 20:10 brunck

RFC3986 does not specifically exclude this syntax, and IIS for example is able to handle it properly. What service are you trying to access that is experiencing the error?

robertmclaws avatar Oct 31 '14 21:10 robertmclaws

http://realtime.mbta.com/developer/api/v2/routes?&api_key=wX9NwuHnZU2ToO7GmGR9uw&format=json

You can use this directly as above, and you get the 400 error with "Invalid query parameter:" Remove the initial "&" and it works. This does use IIS, and may or may not be stopped at the server level, but as you can see it does not work. Others are clearly having this problem too as noted. I wouldn't be surprised if the reason other people are trying to investigate 400 errors, as noted in other issues here, are having the same problem.

brunck avatar Nov 03 '14 13:11 brunck