Dave Gahan
Dave Gahan

Reputation: 299

C# WebAPI - getting URL with parameters passed as QueryString

I've been searching for this problem but non was identical to my case.

I have the following controller:

 public HttpResponseMessage GetMyService(int aType, [FromUri] string streamURL)

streamURL is a parameter that gets a full URL sent by the client.

The client calls the service like that: http://www.myservice.com/.../GetMyService/?aType=1&streamURL=http://www.client.com/?p1=100&p2=200

The problem is that at then end, I get the [FromUri] string streamURL parameter as http://www.client.com/?p1=100 without the &p2=200

This is known and reasonable, but I cannot place any encoding/decoding functionality as the URL is cut at the very beginning.

Any help would be appreciated..

THX

Upvotes: 0

Views: 1578

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038810

The client should properly URL encode the value of the streamURL query string parameter when making the request in order to conform to the HTTP protocol specification:

http://www.myservice.com/.../GetMyService/?aType=1&streamURL=http%3A%2F%2Fwww.client.com%2F%3Fp1%3D100%26p2%3D200

So basically there's nothing you could do on the server side, you should fix the client.

Upvotes: 3

Related Questions