简体   繁体   中英

What is the difference between get query string and URI segment?

Example : get Query String www.domainname.com?var_1=value1&var_2=value2

Example : URI segmnet www.domainname.com/value1/value2

Are they both fulfill same thing?

Which one is recommended to use and when ?

I'm not sure what platform you're working with, but a querystring contains name/value pairs. Any code that accepts parameters passed in via querystring could extract the name/value pairs similarly to it might do so from a posted form.

Using parameters passed in via the URL as you've specified requires some sort of "contract" or for the underlying API to know to expect var_1 and var_2 in the correct places. If I wanted to add a var_3, for example, the underlying code would need to know where to look for that in the URL. If you're using ASP.NET MVC, for example, the default routing uses {controller}/{action}/{id}, so calling [myDomain]/MyController/DoSomething/12 is similar to calling [myDomain]/MyController/DoSomething?id=12. Again, this has to be set up in advance, though.

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