3

I am using swagger ui to test a POST method. I am passing the parameter in URL but it doesn't work.
swagger-ui:

I enter this
Date: 2017-03-03T12:12:12
this is how it goes in
url: https://servername/Results/2017-03-03T12%3A12%3A12


This doesn't work. it return 404 error

but when i pass just the date it works.

Date: 2017-03-03

my method:

[Route("{Results/{date}"), HttpPost]
public Common.CallDetails StartTCISCall(DateTime date)

I have tried this also but it doesn't even catch it as a string.

[Route("{Results/{*date}"), HttpPost]
public Common.CallDetails StartTCISCall(string date)

as soon as i take the colons out it starts to work. What can i do?

Also, for my friend it works locally on VS but when he publishes to IIS it doesn't work and we tried 3 different servers. Why is this?

Many thanks, Please help.

Pat mann
  • 51
  • 1
  • 6

2 Answers2

0

First of all it seems like encoded URLs only work, after the ? for global variables, according to this: URL encoding. So it won't work for routing in c#.

For encoded strings after the question mark u have to decode the string like this:

string result = Server.UrlDecode(date);

Your URL should be build like this:

https://servername/Results?2017-03-03T12%3A12%3A12
Community
  • 1
  • 1
johannespartin
  • 501
  • 3
  • 15
  • That doesn't work. Because it doesn't hit the function if colons are used.If it hits the function then i can decode it. – Pat mann Mar 31 '17 at 07:11
  • Even when i try to capture the parameter in a string it doesn't hit the function. Those : and %3A are causing 404 error. – Pat mann Mar 31 '17 at 07:13
  • oh okay... seems like this won't work. - you only can encode the URL after the ? according to this: http://stackoverflow.com/a/17790994/7729014 – johannespartin Mar 31 '17 at 07:15
  • yeah, I don't why is it not hitting the function and as soon as i take the time part out of datetime and just pass in date. it works. – Pat mann Mar 31 '17 at 14:43
0

It turns out that it was an IIS issue where the server is configured to deny : or % so that's why the encoded URL wasn't getting through either.

After changing the settings on IIS it works.

I hope this helps!

Pat mann
  • 51
  • 1
  • 6
  • Hi I am having a similar problem I have code that passes a timestamp that the user enters to a string variable that is actually an SQL query. When the SQL query gets executed it doesn't work because the colons were changed into percentages. I see that you had a similar problem I don't understand from you answer how you solved it. – Nick Feb 28 '22 at 10:39