MVC interface development package unified request method

  Since the company needs to use interface development, the business logic is written in webapi, and the web side mainly makes calls. In order to facilitate development, the method of unified request is hereby encapsulated, and the page call only needs to write the interface address, not much to say , go directly to the code.

 1 public class ProxyHandlerController : BaseController
 2 {
 3         //
 4         // GET: /ProxyHandler/
 5         public ActionResult ProcessRequest()
 6         {
 7             try
 8             {
 9                 var Request = HttpContext.Request;
10                 string url = Request.QueryString["_URL"].ToString();
11                 var parameters = new Dictionary<string, string>();
12                 if (Request.HttpMethod.ToUpper() == "POST")
13                 {
14                     foreach (var item in Request.Form.Keys)
15                     {
16                         parameters.Add(item.ToString(), Request.Form[item.ToString()].ToString());
17                     }
18                 }
19                 else
20                 {
21                     foreach (var item in Request.QueryString.Keys)
22                     {
23                         if (item.ToString() != "_URL")
24                         {
25                             parameters.Add(item.ToString(), Request.QueryString[item.ToString()].ToString());
26 
27                         }
28                     }
29                 }
31                 var response = HttpRequestHelp.sendRequest(ProjectConst.ApiUrl + url, parameters, Request.HttpMethod, LogOnModel.token);
32                 return Json(response, JsonRequestBehavior.AllowGet);
33             }
34             catch (Exception e)
35             {
36                 return Json(e.Message, JsonRequestBehavior.AllowGet);
37             }
38         }
  }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324965860&siteId=291194637