国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

C# WebApi傳參及Postman調(diào)試

這篇具有很好參考價(jià)值的文章主要介紹了C# WebApi傳參及Postman調(diào)試。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

概述

歡迎來到本文,本篇文章將會(huì)探討C# WebApi中傳遞參數(shù)的方法。在WebApi中,參數(shù)傳遞是一個(gè)非常重要的概念,因?yàn)樗沟梦覀兡軌驈目蛻舳双@取數(shù)據(jù),并將數(shù)據(jù)傳遞到服務(wù)器端進(jìn)行處理。WebApi是一種使用HTTP協(xié)議進(jìn)行通信的RESTful服務(wù),它可以通過各種方式傳遞參數(shù)。在本文中,我們只會(huì)針對(duì)Get和Post討論參數(shù)傳遞的方法,以及如何在C# WebApi中正確地處理它們。

Get

GET請(qǐng)求方法用于獲取資源,通常會(huì)將參數(shù)放在URL的查詢字符串中進(jìn)行傳遞。由于GET請(qǐng)求方法是無狀態(tài)的,因此它通常被用于獲取數(shù)據(jù),而不是修改數(shù)據(jù)。

// 該函數(shù)用于向服務(wù)器發(fā)送GET請(qǐng)求并獲取數(shù)據(jù)
export function getAction(url, query) {
  return request({
    url: url,
    method: 'get',
    params: query
  })
}

1.傳遞字符串參數(shù)

// 前端代碼
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調(diào)用截圖

c# 模擬postman body傳參,C#,.NET Core,.NET Framework,c#,postman,lua

2.傳遞實(shí)體參數(shù)

注意:.Net Core 項(xiàng)目中使用[FromQuery]特性,在.Net Framework 項(xiàng)目中使用[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調(diào)用截圖

c# 模擬postman body傳參,C#,.NET Core,.NET Framework,c#,postman,lua

Post

POST請(qǐng)求方法用于向服務(wù)器端提交數(shù)據(jù),通常會(huì)將參數(shù)放在請(qǐng)求體中進(jìn)行傳遞。POST請(qǐng)求方法通常被用于創(chuàng)建、更新或刪除資源。

// 該函數(shù)用于向服務(wù)器發(fā)送POST請(qǐng)求并獲取數(shù)據(jù)
export function postAction(url, data) {
  return request({
    url: url,
    method: 'post',
    data: data
  })
}

1.傳遞實(shí)體參數(shù)

// 前端代碼
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調(diào)用截圖

c# 模擬postman body傳參,C#,.NET Core,.NET Framework,c#,postman,lua

2.傳遞實(shí)體集合參數(shù)

// 前端代碼
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調(diào)用截圖

c# 模擬postman body傳參,C#,.NET Core,.NET Framework,c#,postman,lua

3.傳遞數(shù)組參數(shù)

// 前端代碼
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調(diào)用截圖

c# 模擬postman body傳參,C#,.NET Core,.NET Framework,c#,postman,lua# 概述

歡迎來到本文,本篇文章將會(huì)探討C# WebApi中傳遞參數(shù)的方法。在WebApi中,參數(shù)傳遞是一個(gè)非常重要的概念,因?yàn)樗沟梦覀兡軌驈目蛻舳双@取數(shù)據(jù),并將數(shù)據(jù)傳遞到服務(wù)器端進(jìn)行處理。WebApi是一種使用HTTP協(xié)議進(jìn)行通信的RESTful服務(wù),它可以通過各種方式傳遞參數(shù)。在本文中,我們只會(huì)針對(duì)Get和Post討論參數(shù)傳遞的方法,以及如何在C# WebApi中正確地處理它們。

Get

GET請(qǐng)求方法用于獲取資源,通常會(huì)將參數(shù)放在URL的查詢字符串中進(jìn)行傳遞。由于GET請(qǐng)求方法是無狀態(tài)的,因此它通常被用于獲取數(shù)據(jù),而不是修改數(shù)據(jù)。

// 該函數(shù)用于向服務(wù)器發(fā)送GET請(qǐng)求并獲取數(shù)據(jù)
export function getAction(url, query) {
  return request({
    url: url,
    method: 'get',
    params: query
  })
}

1.傳遞字符串參數(shù)

// 前端代碼
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調(diào)用截圖

c# 模擬postman body傳參,C#,.NET Core,.NET Framework,c#,postman,lua

2.傳遞實(shí)體參數(shù)

注意:.Net Core 項(xiàng)目中使用[FromQuery]特性,在.Net Framework 項(xiàng)目中使用[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調(diào)用截圖

c# 模擬postman body傳參,C#,.NET Core,.NET Framework,c#,postman,lua

Post

POST請(qǐng)求方法用于向服務(wù)器端提交數(shù)據(jù),通常會(huì)將參數(shù)放在請(qǐng)求體中進(jìn)行傳遞。POST請(qǐng)求方法通常被用于創(chuàng)建、更新或刪除資源。

// 該函數(shù)用于向服務(wù)器發(fā)送POST請(qǐng)求并獲取數(shù)據(jù)
export function postAction(url, data) {
  return request({
    url: url,
    method: 'post',
    data: data
  })
}

1.傳遞實(shí)體參數(shù)

// 前端代碼
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調(diào)用截圖

c# 模擬postman body傳參,C#,.NET Core,.NET Framework,c#,postman,lua

2.傳遞實(shí)體集合參數(shù)

// 前端代碼
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調(diào)用截圖

c# 模擬postman body傳參,C#,.NET Core,.NET Framework,c#,postman,lua

3.傳遞數(shù)組參數(shù)

// 前端代碼
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調(diào)用截圖

c# 模擬postman body傳參,C#,.NET Core,.NET Framework,c#,postman,lua文章來源地址http://www.zghlxwxcb.cn/news/detail-852152.html

到了這里,關(guān)于C# WebApi傳參及Postman調(diào)試的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Dynamics 365 設(shè)置Postman environment For WebAPI

    Dynamics 365 設(shè)置Postman environment For WebAPI

    ? ? ?在官網(wǎng)看到這么一篇\\\"Set up a Postman environment\\\",不用在Azure AD中注冊(cè)application就可以在postman中構(gòu)建WebAPI,對(duì)于開發(fā)者來說確實(shí)能幫助我們更快的上手開發(fā),但國內(nèi)用的是21V,所以本篇就來記錄下驗(yàn)證后在21V中的可用性。 ? ? ? 首先根據(jù)博文中的描述,我先找了個(gè)galobal的環(huán)

    2024年02月11日
    瀏覽(26)
  • Postman傳參的JSON格式

    實(shí)體類: json格式: 1.JSON數(shù)值({ “key” : value}) 2.JSON字符串({ “key” : “value”}) 3.JSON數(shù)組({ “key” : [value]}) 4.JSON對(duì)象({ “key” : {value}}) 5.JSON對(duì)象數(shù)組({ “key” : [{“key1”: “value1”},{“key2”: “value2”}]}) 6.JSON數(shù)組對(duì)象({“key”:{“key1”:[value1,value2]}})

    2024年02月12日
    瀏覽(16)
  • ApiPost/Postman 傳參賦值詳解

    ApiPost/Postman 傳參賦值詳解

    當(dāng)使用getMapping()時(shí),使用@requestParam(\\\"strs\\\") ListString strs ApiPost 還有一種寫法: ? ? 當(dāng)使用PostMapping()時(shí),使用requestBody ? ?APIPost 即: 如果是ListInteger 詳細(xì)說一下: ? ?如果使用requestParam 注意 @RequestParam 里的 value 一定要帶上中括號(hào): ? 或者 ? ? ? ? ? ? ApiPost 多種情況: ? ?

    2024年02月03日
    瀏覽(16)
  • postman批量執(zhí)行請(qǐng)求,通過json傳參

    postman批量執(zhí)行請(qǐng)求,通過json傳參

    \\\"authUid\\\":\\\" {{authUid}} \\\", 加粗為需要替換的參數(shù) 可通過Excel自動(dòng)填充功能構(gòu)造數(shù)據(jù) 學(xué)習(xí)借鑒:https://www.cnblogs.com/l0923/p/13419986.html

    2024年02月17日
    瀏覽(23)
  • Postman的FormData傳參用法詳解

    ????????今年上半年因?yàn)樽霎呍O(shè)的原因,有自己接觸到后端,也是用過了postman去測(cè)試接口,看到了postman那邊的參數(shù)形式,一直對(duì)這個(gè)formData有想法。 ????????在做畢設(shè)前后端對(duì)接接口過程中,一般get或者delete請(qǐng)求我都會(huì)使用url拼接的形式,因?yàn)楦鶕?jù)restAPI格式,這兩者

    2024年02月11日
    瀏覽(24)
  • Postman傳參是Json字符串

    Postman傳參是Json字符串

    進(jìn)入Postman以后,點(diǎn)擊Body,點(diǎn)擊raw,將Json參數(shù)復(fù)制到空白框里,點(diǎn)擊末尾,選擇JSON格式。

    2024年02月11日
    瀏覽(15)
  • postman----傳參格式(json格式、表單格式)

    postman----傳參格式(json格式、表單格式)

    ? 本文主要講解postman使用post請(qǐng)求方法的2中傳參方式:json格式、表單格式 首先了解下,postman進(jìn)行接口測(cè)試,必須條件是: ?請(qǐng)求地址 ?請(qǐng)求協(xié)議 ?請(qǐng)求方式 ?請(qǐng)求頭 ?參數(shù) json格式 先看一下接口文檔,根據(jù)接口文檔,在postman中填入必要的參數(shù)信息 post請(qǐng)求方式,使用?

    2024年02月14日
    瀏覽(20)
  • 多個(gè)對(duì)象入?yún)ostMan測(cè)試傳參方式

    多個(gè)對(duì)象入?yún)ostMan測(cè)試傳參方式

    多個(gè)對(duì)象入?yún)?使用postMan測(cè)試 但是怎么傳值后端都接收不到數(shù)據(jù)? 前言:因?yàn)樾枰獙懸粋€(gè)分頁查詢 但是組里現(xiàn)場(chǎng)的傳值方式都是這種所以 就遇到了兩個(gè)參數(shù)不知道怎么傳值的情況 在這寫了一個(gè)簡單的方法測(cè)試PostMan怎么傳值兩個(gè)對(duì)象的情況 ?簡單的測(cè)試 接口代碼: 其中實(shí)體類

    2024年02月16日
    瀏覽(19)
  • web-view往h5傳參及傳參亂碼問題

    web-view往h5傳參及傳參亂碼問題

    1、微信端的操作 往wxml中配置web-view 并在對(duì)應(yīng)js中動(dòng)態(tài)設(shè)置路徑的參數(shù) 在需要的地方修改其路徑參數(shù) 2、h5端(接受上面?zhèn)鬟M(jìn)來的參數(shù)) 注:這里建議如果h5是vue項(xiàng)目的話,可以本地映射一個(gè)地址出去。在vue.config.js下配置devServer--host設(shè)置為本機(jī)ip地址,接著小程序接入該地址用

    2024年02月09日
    瀏覽(20)
  • postman form-data傳參java實(shí)現(xiàn)

    postman form-data傳參java實(shí)現(xiàn)

    java實(shí)現(xiàn): 第二種方式: 導(dǎo)入依賴:

    2024年02月12日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包