gpt4 book ai didi

javascript - 如何通过 Jquery 向 C# 方法发送请求并获取其参数

转载 作者:行者123 更新时间:2023-12-01 15:45:40 25 4
gpt4 key购买 nike

有什么方法可以调用 API 以了解其所需参数吗?
例如,如果有一个 Controller 有一个方法以名称和日期作为参数

[HttpPost]
public string testUrl(string name,string date)
{
return "success";
}
现在我要做的是使动态表单采用 API URL 并生成所有必需的输入,因此我必须找到某种方法来调用 URL 并返回所需的参数。

最佳答案

快速而肮脏的方法是对其进行硬编码:

[HttpPost]
public string testUrl(string name,string date)
{
return "success";
}

public APISchema TestUrlSchema(){
return new APISchema() {
Parameters = new List<Parameter>(){
new Parameter(){ Name = "name", Type = "String" },
new Parameter(){ Name = "date", Type = "String" }
}
};
}

public class APISchema {
public List<Parameter> Parameters {get;set;}
}

public class Parameter {
public String Name {get;set;}
public String Type {get;set;}
}
您可以使用 Reflection如果您想为大量操作执行此操作,请自动生成它。
正如评论所提到的,有图书馆 Swagger这将为您做到这一点。

关于javascript - 如何通过 Jquery 向 C# 方法发送请求并获取其参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63111861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com