How to create API in Asp.net MVC parameters separeted with '&' symbole ?
like :
Code
http://localhost:22332/api/authorize?user=ury&session=token&item=an_itemhttp://localhost:22332/api/authorize?user=ury&session=token&item=an_itemKnow the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Bhuvanesh MohankumarRank #310 · 8.1K reputationPosted May 13, 2016, 1:08 AM EDT
Yes this is possible, that to have a query stringtype values to be passed to the web api service.
please lookat this example and you can understand the same.
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; namespace Thrita.Web.Api.FreeWebApi.Controllers { public class ValuesController : ApiController { // GET api/values public IEnumerable Get() { var allUrlKeyValues = ControllerContext.Request.GetQueryNameValuePairs(); string p1Val = allUrlKeyValues.SingleOrDefault(x => x.Key == "p1").Value; string p2Val = allUrlKeyValues.SingleOrDefault(x => x.Key == "p2").Value; string p3Val = allUrlKeyValues.SingleOrDefault(x => x.Key == "p3").Value; return new string[] { "value1", "value2" , p1Val, p2Val, p3Val }; } // GET api/values/5 public string Get(int id) { return "value"; } // POST api/values public void Post([FromBody]string value) { } // PUT api/values/5 public void Put(int id, [FromBody]string value) { } // DELETE api/values/5 public void Delete(int id) { } } }