1

Usually we consume rest services from ajax from html pages. Sometimes we need to consume rest services from controller actions. And send this response to clients. My Project is asp.net mvc.

For example I have a rest service url that takes parameter username and password like following. https://myservice.com/token?username=asd&password=123 this service returns JSON result.

So I need a Proxy controller action that sends request to "myservice.com"

public class TokenController : Controller
{
    public JsonResult Get()
    {
        // ??? send request to myservice.com and get json ????
        return Json(new { token = tkn }, JsonRequestBehavior.AllowGet);
    }
}

Is there a practical way to sent request and get token from Controller's action method. WebClient or else?

barteloma
  • 6,403
  • 14
  • 79
  • 173
  • [This](http://stackoverflow.com/questions/3572627/how-to-call-an-external-url-from-a-asp-net-mvc-solution) might help your cause. – Andrei V Jan 14 '14 at 12:16
  • Duplicate of http://stackoverflow.com/questions/8883656/how-to-consume-a-restful-service-in-net/10035401#10035401 (and others of the flavor "How do I perform a HTTP request in .NET"). Personally I would recommend using Restsharp (http://restsharp.org/) or Ramone (https://github.com/JornWildt/Ramone) – Jørn Wildt Jan 14 '14 at 12:45

0 Answers0