c# - c# Web API 在使用 React Native Fetch Call 时在 Endpoint 调用 Post 未触发
问题描述
API 控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace LinkrWebApi.Controllers
{
public class ValuesController : ApiController
{
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[Route("api/values/{country}/{type}")]
public string Get(string country, string type)
{
return "value";
}
public class GetResource
{
public string countryName { set; get; }
public string imageLogo { set; get; }
public string desc { set; get; }
public string link { set; get; }
}
// POST api/values
public void Post(string countryName)
{
}
// PUT api/values/5
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/values/5
public void Delete(int id)
{
}
}
}
还有我的 Fetch 调用:
fetch('https://localhost:44374/api/values', {
method: 'post',
body: "countryName=sc",
headers: new Headers({
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
})
}).then(function(response) {
return response.json();
}).then(function(data) {
//navigation.navigate('FinalResource', { companyName: route.params.companyName, imageLogo: route.params.imageLogo, desc: txtD, link: txtL })
});
但是我的 Web API 中的 Post 方法没有触发,get 工作但不是 post,任何人都可以看到错误吗?
解决方案
推荐阅读
- python - 通过套接字从 C++ 服务器向 Python 客户端发送数据时出现问题
- shell - 使用 sed 在一行中的其他单词和数字之间交换单词
- c# - 我可以将语言列表链接到单选按钮吗?
- php - 从open api导入数据并使用与mysql循环相结合的循环
- visual-studio-code - 如何在 settings.json 中删除 VS Code 用户设置
- angular - 从一台 Angular 7 服务器提供数据和 Web 视图
- python - 吉普错误!堆栈错误:找不到 Python 可执行文件
- css - 设置全局 Sass 变量
- php - Laravel 5.8 更新 eloquent 模型并在一行中调用访问器?
- node.js - 我怎样才能找到并更新许多文件?