reactjs - 将 axios 发布请求反应到 wcf Web 服务
问题描述
我正在尝试将数据从反应应用程序发布到 wcf 服务类。它是一个简单的对象,只有名称年龄和性别。正在从反应应用程序调用该服务,但没有数据。如果我使用获取请求和参数传递数据正在传递给服务,但我想使用发布请求。是否需要匹配 wcf 服务类中的字段名称。
为了在反应组件中进行测试,我正在使用此代码
const headers = {
'content-type': 'application/json'
}
const puser = {
Name:'Test',
Age:'23',
Gender:'F',
}
axios.post('http://localhost:3292/myService.svc/adduser',{headers:headers}, puser)
.then(res=> {
console.log(res.data)
})
在 wcf 服务中,类代码是
public class UserClass
{
string name;
int age;
string gender;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
public string Gender
{
get
{
return gender;
}
set
{
gender = value;
}
}
}
并在服务电话中
public string AddUser(List<User> U)
{
UserClass usr = new UserClass();
return "success";
}
解决方案
Axios post 方法需要data
作为第二个参数。尝试puser
与{headers}
.
https://github.com/axios/axios#axiosposturl-data-config
推荐阅读
- vue.js - vuex typeError中的vue-progressbar
- json - Nunjucks 模板引擎中的动态标题和描述
- mysql - 无法在程序中连接到 MySQL 服务器数据库 [VB]
- ios - NSKeyedUnarchiver.unarchiveObjectWithFile 在加载从不同目标创建的类时崩溃
- python - 如何使用两个用户输入来简化 if elif 代码?
- java - 实现设计模式和 Spring MVC
- java - Spring JPA - 一对多 - 重新育儿
- c# - 如何在实体框架配置中播种动态数据
- python - How to get all data out of many to many field?
- sql-server - 如何在 SQL Server 2008 R2 中创建新的数据库图表时修复“无效的类字符串(MS Visual Database Tools)”