WebApi开发框架:使用HttpGet方式调用WebAPI接口
WebApi开发框架:使用HttpGet方式调用WebAPI接口
接口参数:
测试接口:
扫一扫加微信
在DoController控制器添加一个接口方法,注意接口的参数对象是采用Uri参数转换, 定义[FromUri]特性。
C# Code:
/// <summary>
/// 通过URL获取OSS图片
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet]
[ActionName("ossimg")]
public IUserResponse DoGetOSSImage([FromUri] ModelAliOSSGet request)
{
if (request == null || request.Apikey != "ZD51C485-B611-451C-915F-4BA3900E7CAC")
return new ModelResponse { Code = -1, Message = "请求参数错误!" };
else
{
string imgUrl = ImageHelper.getImageUrl(request.Phone, request.ImageType, "");
return new ModelResponse
{
Code = 0,
Data = imgUrl,//返回图片url地址
Message = "",
};
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// 通过URL获取OSS图片
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet]
[ActionName("ossimg")]
public IUserResponse DoGetOSSImage([FromUri] ModelAliOSSGet request)
{
if (request == null || request.Apikey != "ZD51C485-B611-451C-915F-4BA3900E7CAC")
return new ModelResponse { Code = -1, Message = "请求参数错误!" };
else
{
string imgUrl = ImageHelper.getImageUrl(request.Phone, request.ImageType, "");
return new ModelResponse
{
Code = 0,
Data = imgUrl,//返回图片url地址
Message = "",
};
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
接口参数:
C# Code:
public class ModelAliOSSGet
{
public string Apikey { get; set; }
public string Phone { get; set; }
public string ImageType { get; set; }
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
public string Apikey { get; set; }
public string Phone { get; set; }
public string ImageType { get; set; }
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
测试接口:
C# Code:
ModelAliOSSGet model = new ModelAliOSSGet
{
Phone = "15846647518",
ImageType = "carimage",
Apikey = "ZD51C485-B611-451C-915F-4BA3900E7CAC"
};
string url = "http://localhost:16788/api/do/ossimg";
//序列化实体对象,把属性转换为URL参数字符串
string param = WebApiTools.GetUrlParam(model);
{
Phone = "15846647518",
ImageType = "carimage",
Apikey = "ZD51C485-B611-451C-915F-4BA3900E7CAC"
};
string url = "http://localhost:16788/api/do/ossimg";
//序列化实体对象,把属性转换为URL参数字符串
string param = WebApiTools.GetUrlParam(model);
//HttpGet方式调用webapi接口
string result = WebApiTools.Get(url, param);
//来源:C/S框架网 | www.csframework.com | QQ:23404761
string result = WebApiTools.Get(url, param);
//来源:C/S框架网 | www.csframework.com | QQ:23404761
扫一扫加微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网