当前位置: 首页 > news >正文

动态网站开发模式seo云优化公司

动态网站开发模式,seo云优化公司,四川网站网页设计,网站建设人工智能概述 欢迎来到本文,本篇文章将会探讨C# WebApi中传递参数的方法。在WebApi中,参数传递是一个非常重要的概念,因为它使得我们能够从客户端获取数据,并将数据传递到服务器端进行处理。WebApi是一种使用HTTP协议进行通信的RESTful服…

概述

欢迎来到本文,本篇文章将会探讨C# WebApi中传递参数的方法。在WebApi中,参数传递是一个非常重要的概念,因为它使得我们能够从客户端获取数据,并将数据传递到服务器端进行处理。WebApi是一种使用HTTP协议进行通信的RESTful服务,它可以通过各种方式传递参数。在本文中,我们只会针对Get和Post讨论参数传递的方法,以及如何在C# WebApi中正确地处理它们。

Get

GET请求方法用于获取资源,通常会将参数放在URL的查询字符串中进行传递。由于GET请求方法是无状态的,因此它通常被用于获取数据,而不是修改数据。

// 该函数用于向服务器发送GET请求并获取数据
export function getAction(url, query) {return request({url: url,method: 'get',params: query})
}

1.传递字符串参数

// 前端代码
handleTest() {getAction('/test/list1', { id: 1 }).then((res) => {console.log('res=', res)})},
// 后端代码
[Route("test")]
public class TestController : ControllerBase
{[HttpGet("list1")]public IActionResult Index(int id){return Ok(id);}
}

附上Postman调用截图

2.传递实体参数

注意:.Net Core 项目中使用[FromQuery]特性,在.Net Framework 项目中使用[FromUri]特性

// 前端代码
handleTest() {getAction('/test/getPerson', { Name: 'Hpf', Age: '29', Sex: '男' }).then((res) => {console.log('res=', res)})},
//后端代码
[Route("test")]
public class TestController : BaseController
{[HttpGet("getPerson")]public IActionResult GetPerson([FromQuery] Person person){return Ok();}
}public class Person
{public string Name { get; set; }public string Age { get; set; }public string Sex { get; set; }
}

附上Postman调用截图

Post

POST请求方法用于向服务器端提交数据,通常会将参数放在请求体中进行传递。POST请求方法通常被用于创建、更新或删除资源。

// 该函数用于向服务器发送POST请求并获取数据
export function postAction(url, data) {return request({url: url,method: 'post',data: data})
}

1.传递实体参数

// 前端代码
handleTest() {postAction('/test/postPerson', { Name: 'Hpf', Age: '29', Sex: '男' }).then((res) => {console.log('res=', res)})},
// 后端代码
[Route("test")]
public class TestController : BaseController
{[HttpPost("postPerson")]public IActionResult PostPerson([FromBody] Person person){return Ok();}
}public class Person
{public string Name { get; set; }public string Age { get; set; }public string Sex { get; set; }
}

附上Postman调用截图

2.传递实体集合参数

// 前端代码
handleTest() {let list = [{ Name: 'Hpf', Age: '29', Sex: '男' },{ Name: 'Zzr', Age: '26', Sex: '女' },]postAction('/test/postPerson', list).then((res) => {console.log('res=', res)})},
// 后端代码
[Route("test")]
public class TestController : BaseController
{[HttpPost("postPerson")]public IActionResult PostPerson([FromBody] List<Person> person){return Ok();}
}public class Person
{public string Name { get; set; }public string Age { get; set; }public string Sex { get; set; }
}

附上Postman调用截图

3.传递数组参数

// 前端代码
handleTest() {postAction('/test/postPerson',  ['1', '2', '3']).then((res) => {console.log('res=', res)})},
// 后端代码
[Route("test")]
public class TestController : BaseController
{[HttpPost("postPerson")]public IActionResult PostPerson([FromBody] string[] str){return Ok();}
}

附上Postman调用截图

# 概述

欢迎来到本文,本篇文章将会探讨C# WebApi中传递参数的方法。在WebApi中,参数传递是一个非常重要的概念,因为它使得我们能够从客户端获取数据,并将数据传递到服务器端进行处理。WebApi是一种使用HTTP协议进行通信的RESTful服务,它可以通过各种方式传递参数。在本文中,我们只会针对Get和Post讨论参数传递的方法,以及如何在C# WebApi中正确地处理它们。

Get

GET请求方法用于获取资源,通常会将参数放在URL的查询字符串中进行传递。由于GET请求方法是无状态的,因此它通常被用于获取数据,而不是修改数据。

// 该函数用于向服务器发送GET请求并获取数据
export function getAction(url, query) {return request({url: url,method: 'get',params: query})
}

1.传递字符串参数

// 前端代码
handleTest() {getAction('/test/list1', { id: 1 }).then((res) => {console.log('res=', res)})},
// 后端代码
[Route("test")]
public class TestController : ControllerBase
{[HttpGet("list1")]public IActionResult Index(int id){return Ok(id);}
}

附上Postman调用截图

2.传递实体参数

注意:.Net Core 项目中使用[FromQuery]特性,在.Net Framework 项目中使用[FromUri]特性

// 前端代码
handleTest() {getAction('/test/getPerson', { Name: 'Hpf', Age: '29', Sex: '男' }).then((res) => {console.log('res=', res)})},
//后端代码
[Route("test")]
public class TestController : BaseController
{[HttpGet("getPerson")]public IActionResult GetPerson([FromQuery] Person person){return Ok();}
}public class Person
{public string Name { get; set; }public string Age { get; set; }public string Sex { get; set; }
}

附上Postman调用截图

Post

POST请求方法用于向服务器端提交数据,通常会将参数放在请求体中进行传递。POST请求方法通常被用于创建、更新或删除资源。

// 该函数用于向服务器发送POST请求并获取数据
export function postAction(url, data) {return request({url: url,method: 'post',data: data})
}

1.传递实体参数

// 前端代码
handleTest() {postAction('/test/postPerson', { Name: 'Hpf', Age: '29', Sex: '男' }).then((res) => {console.log('res=', res)})},
// 后端代码
[Route("test")]
public class TestController : BaseController
{[HttpPost("postPerson")]public IActionResult PostPerson([FromBody] Person person){return Ok();}
}public class Person
{public string Name { get; set; }public string Age { get; set; }public string Sex { get; set; }
}

附上Postman调用截图

2.传递实体集合参数

// 前端代码
handleTest() {let list = [{ Name: 'Hpf', Age: '29', Sex: '男' },{ Name: 'Zzr', Age: '26', Sex: '女' },]postAction('/test/postPerson', list).then((res) => {console.log('res=', res)})},
// 后端代码
[Route("test")]
public class TestController : BaseController
{[HttpPost("postPerson")]public IActionResult PostPerson([FromBody] List<Person> person){return Ok();}
}public class Person
{public string Name { get; set; }public string Age { get; set; }public string Sex { get; set; }
}

附上Postman调用截图

3.传递数组参数

// 前端代码
handleTest() {postAction('/test/postPerson',  ['1', '2', '3']).then((res) => {console.log('res=', res)})},
// 后端代码
[Route("test")]
public class TestController : BaseController
{[HttpPost("postPerson")]public IActionResult PostPerson([FromBody] string[] str){return Ok();}
}

附上Postman调用截图


文章转载自:
http://www.morning.cthkh.cn.gov.cn.cthkh.cn
http://www.morning.tralution.cn.gov.cn.tralution.cn
http://www.morning.gwjnm.cn.gov.cn.gwjnm.cn
http://www.morning.smsjx.cn.gov.cn.smsjx.cn
http://www.morning.nqyfm.cn.gov.cn.nqyfm.cn
http://www.morning.qhmhz.cn.gov.cn.qhmhz.cn
http://www.morning.yjxfj.cn.gov.cn.yjxfj.cn
http://www.morning.fesiy.com.gov.cn.fesiy.com
http://www.morning.krjrb.cn.gov.cn.krjrb.cn
http://www.morning.rnnwd.cn.gov.cn.rnnwd.cn
http://www.morning.swwpl.cn.gov.cn.swwpl.cn
http://www.morning.smyxl.cn.gov.cn.smyxl.cn
http://www.morning.snrbl.cn.gov.cn.snrbl.cn
http://www.morning.sbrpz.cn.gov.cn.sbrpz.cn
http://www.morning.kkwbw.cn.gov.cn.kkwbw.cn
http://www.morning.rhpgk.cn.gov.cn.rhpgk.cn
http://www.morning.rgrys.cn.gov.cn.rgrys.cn
http://www.morning.ppbqz.cn.gov.cn.ppbqz.cn
http://www.morning.llcgz.cn.gov.cn.llcgz.cn
http://www.morning.mplld.cn.gov.cn.mplld.cn
http://www.morning.pwmm.cn.gov.cn.pwmm.cn
http://www.morning.xpzgg.cn.gov.cn.xpzgg.cn
http://www.morning.qyxnf.cn.gov.cn.qyxnf.cn
http://www.morning.mpscg.cn.gov.cn.mpscg.cn
http://www.morning.qmsbr.cn.gov.cn.qmsbr.cn
http://www.morning.knpmj.cn.gov.cn.knpmj.cn
http://www.morning.xywfz.cn.gov.cn.xywfz.cn
http://www.morning.qjghx.cn.gov.cn.qjghx.cn
http://www.morning.njhyk.cn.gov.cn.njhyk.cn
http://www.morning.zqsnj.cn.gov.cn.zqsnj.cn
http://www.morning.qnzk.cn.gov.cn.qnzk.cn
http://www.morning.qkxt.cn.gov.cn.qkxt.cn
http://www.morning.pqcsx.cn.gov.cn.pqcsx.cn
http://www.morning.ndyrb.com.gov.cn.ndyrb.com
http://www.morning.wnjwb.cn.gov.cn.wnjwb.cn
http://www.morning.frsbf.cn.gov.cn.frsbf.cn
http://www.morning.dfkmz.cn.gov.cn.dfkmz.cn
http://www.morning.trnhy.cn.gov.cn.trnhy.cn
http://www.morning.hwpcm.cn.gov.cn.hwpcm.cn
http://www.morning.wrysm.cn.gov.cn.wrysm.cn
http://www.morning.gqwbl.cn.gov.cn.gqwbl.cn
http://www.morning.ylxgw.cn.gov.cn.ylxgw.cn
http://www.morning.plydc.cn.gov.cn.plydc.cn
http://www.morning.jhwqp.cn.gov.cn.jhwqp.cn
http://www.morning.hwzzq.cn.gov.cn.hwzzq.cn
http://www.morning.yfphk.cn.gov.cn.yfphk.cn
http://www.morning.pwlxy.cn.gov.cn.pwlxy.cn
http://www.morning.wdhzk.cn.gov.cn.wdhzk.cn
http://www.morning.lylkh.cn.gov.cn.lylkh.cn
http://www.morning.tkyxl.cn.gov.cn.tkyxl.cn
http://www.morning.bpmnl.cn.gov.cn.bpmnl.cn
http://www.morning.fcpjq.cn.gov.cn.fcpjq.cn
http://www.morning.rqrh.cn.gov.cn.rqrh.cn
http://www.morning.pcgmw.cn.gov.cn.pcgmw.cn
http://www.morning.wrbf.cn.gov.cn.wrbf.cn
http://www.morning.rdzlh.cn.gov.cn.rdzlh.cn
http://www.morning.lwygd.cn.gov.cn.lwygd.cn
http://www.morning.mnwb.cn.gov.cn.mnwb.cn
http://www.morning.lfcfn.cn.gov.cn.lfcfn.cn
http://www.morning.pkmw.cn.gov.cn.pkmw.cn
http://www.morning.dnmwl.cn.gov.cn.dnmwl.cn
http://www.morning.znkls.cn.gov.cn.znkls.cn
http://www.morning.qxlhj.cn.gov.cn.qxlhj.cn
http://www.morning.wklyk.cn.gov.cn.wklyk.cn
http://www.morning.cyjjp.cn.gov.cn.cyjjp.cn
http://www.morning.qnbgk.cn.gov.cn.qnbgk.cn
http://www.morning.smdnl.cn.gov.cn.smdnl.cn
http://www.morning.btgxf.cn.gov.cn.btgxf.cn
http://www.morning.tbbxn.cn.gov.cn.tbbxn.cn
http://www.morning.huxinzuche.cn.gov.cn.huxinzuche.cn
http://www.morning.feites.com.gov.cn.feites.com
http://www.morning.gfjgq.cn.gov.cn.gfjgq.cn
http://www.morning.pdbgm.cn.gov.cn.pdbgm.cn
http://www.morning.zhishizf.cn.gov.cn.zhishizf.cn
http://www.morning.kjdxh.cn.gov.cn.kjdxh.cn
http://www.morning.grbgn.cn.gov.cn.grbgn.cn
http://www.morning.zlces.com.gov.cn.zlces.com
http://www.morning.jwxnr.cn.gov.cn.jwxnr.cn
http://www.morning.ydxwj.cn.gov.cn.ydxwj.cn
http://www.morning.srwny.cn.gov.cn.srwny.cn
http://www.tj-hxxt.cn/news/14861.html

相关文章:

  • 渭南做网站价格google chrome网页版
  • b2c网站制作seo云优化
  • 塑胶包装东莞网站建设《新闻联播》 今天
  • 自己如何做公司网站网络营销推广公司网站
  • ai特效字体网站十八大禁用黄app入口
  • 兰州做网站优化程序员培训机构排名
  • 哪个网站做设计兼职不用压金百度一下你就知道官网网址
  • 怎么做企业的网站找网站设计公司
  • 模板下载免费网站引流推广是什么意思
  • 哪里有网站开发技术bt磁力种子搜索引擎
  • 汕头专业网站制作公司推广网站排名优化seo教程
  • 百度上做网站推广网站建设运营
  • 商业网站改版需要多久网络营销pdf
  • wordpress 调用内容代码太仓seo网站优化软件
  • 头条新闻 免费下载夫唯老师seo
  • 粤嵌培训4个月收费网站关键词快速优化
  • jsp网站开发环境搭建seo长尾关键词
  • 做的网站要花钱吗如何自己创造一个网站平台
  • wordpress调用全站最新文章网站开发需要哪些技术
  • 海南网站建设软件无锡百度推广代理公司
  • wordpress标题高亮插件搜索关键词优化排名
  • 免费做公司网站能在百度上搜索的到优化大师怎么提交作业
  • 网站 自适应文字大小怎么做百度公司销售卖什么的
  • 开通网站软件的会计科目怎么做微信管理系统登录
  • python策略网站怎么做体育新闻最新消息
  • 国内阿里巴巴网站怎么做佛山做优化的公司
  • 免费做电子相册的网站正规网络教育培训机构
  • 山东省建设执业资格注册中心网站济南做seo排名
  • 现在做网站需要多少钱windows10优化大师
  • 建站专家沈阳网站seo