客户端使用HTTPGET请求调用WebApi指定FromUri参数对象模型的接口
客户端使用HTTPGET请求调用WebApi指定FromUri参数对象模型的接口
客户端调用:
服务端WebApi接口:
C# Code:
/// <summary>
/// 根据客户编码获取指定客户资料
/// 演示客户端采用HTTPGET请求调用WebApi指定FromUri参数的接口
/// </summary>
/// <param name="request">请求</param>
/// <returns></returns>
[HttpGet]
[ActionName("GetCustomer")]
public IUserResponse GetCustomer([FromUri] ModelRequest request)
{
AssertRequest(request);
//转换为模型
ModelRequestAction action = new ModelRequestAction(request)
{
Action = 800001,
Operation = "GetCustomer",
};
return CommandHandler.ProcessRequest(this.Request, action, LogManager.Log);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
/// <summary>
/// 根据客户编码获取指定客户资料
/// 演示客户端采用HTTPGET请求调用WebApi指定FromUri参数的接口
/// </summary>
/// <param name="request">请求</param>
/// <returns></returns>
[HttpGet]
[ActionName("GetCustomer")]
public IUserResponse GetCustomer([FromUri] ModelRequest request)
{
AssertRequest(request);
//转换为模型
ModelRequestAction action = new ModelRequestAction(request)
{
Action = 800001,
Operation = "GetCustomer",
};
return CommandHandler.ProcessRequest(this.Request, action, LogManager.Log);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
C# Code:
//Request请求主体对象
ModelRequest mr = new ModelRequest();
mr.Timestamp = DateTime.Now.ToString("yyyyMMddHHmmssfff");
mr.ApiKey = PrivateData.apikey;
mr.Data = "C00001342";//客户编码
mr.Sign = CryptoHelper.ToMD5(mr.ApiKey + mr.Data + PrivateData.secret + mr.Timestamp);//Sign数字签名
txtMethod.Text = "api/do/GetCustomer";
txtParam.Text = WebApiTools.GetUrlParam(mr);
string url = txtURL.Text + txtMethod.Text;
string result = WebApiTools.Get(url, txtParam.Text);//调用GET接口
txtResponse.Text = result;
//来源:C/S框架网(www.csframework.com) QQ:23404761
//Request请求主体对象
ModelRequest mr = new ModelRequest();
mr.Timestamp = DateTime.Now.ToString("yyyyMMddHHmmssfff");
mr.ApiKey = PrivateData.apikey;
mr.Data = "C00001342";//客户编码
mr.Sign = CryptoHelper.ToMD5(mr.ApiKey + mr.Data + PrivateData.secret + mr.Timestamp);//Sign数字签名
txtMethod.Text = "api/do/GetCustomer";
txtParam.Text = WebApiTools.GetUrlParam(mr);
string url = txtURL.Text + txtMethod.Text;
string result = WebApiTools.Get(url, txtParam.Text);//调用GET接口
txtResponse.Text = result;
//来源:C/S框架网(www.csframework.com) QQ:23404761
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网