当我尝试在我的web api上发布一篇文章时,我得到了一个错误404,我不确定为什么我会得到它,url和一切都是正确的。
http://10.0.1.96/testwebapi/api/case/UpdateCasePersonal/?id=4584&forename=Andy&surname=Wilson&email=example@example.co.uk&telephone=0166%20254%204876&mobile=0733333333&title=Mr
这是我的web api代码的Url,接下来我将把它放入
[HttpPost]
[Route("updatecasepersonal/")]
public string UpdateCasePersonal(string Caseid, string Title, string Forename, string Surname, string Telephone, string Email, string Mobile)
{
using (SqlConnection con = new SqlConnection(conString))
{
con.Open();
var query = $@"UPDATE TestDB.dbo.[crm-data] SET Title=" + Title + ", Forename=" + Forename + ", Surname=" + Surname + ", Telephone=" + Telephone + ", Email=" + Email + ", Mobile=" + Mobile + " WHERE Caseid=" + Caseid;
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.CommandType = CommandType.Text;
var dtb = new DataTable();
var da = new SqlDataAdapter(cmd);
da.Fill(dtb);
return "Done";
}
}
}
另外,我这样更新我的表也是正确的吗?或者我做错了所有的事情,因为我还不能流利地使用c#
如果需要,可以提供更多代码
这是我调用api的代码
onUpdateClick(e) {
this.setState({
updatedForename: this.state.Case.Forename,
updatedSurname: this.state.Case.Surname,
updatedHomeTelephone: this.state.Case.Telephone,
updatedMobileTelephone: this.state.Case.Mobile,
updatedEmail: this.state.Case.Email,
updatedTitle: this.state.titleValue,
updatedPurpose: this.state.purposeValue,
updatedMaritalStatus: this.state.maritalValue,
updatedEmpStatus: this.state.empValue,
}, function () {
var id = this.state.Case.Caseid;
var forename = this.state.updatedForename;
var surname = this.state.updatedSurname;
var email = this.state.updatedEmail;
var homeTelephone = this.state.updatedHomeTelephone;
var mobileTelephone = this.state.updatedMobileTelephone;
var title = this.state.updatedTitle;
axios.post('http://10.0.1.96/testwebapi/api/case/UpdateCasePersonal/', {
params: {
id: id,
forename: forename,
surname: surname,
email: email,
telephone: homeTelephone,
mobile: mobileTelephone,
title: title
}
}).then(function (res) {
}).catch(function (err) {
});
});
this.setState({
hasSaved: true
});
}
https://stackoverflow.com/questions/45219786
复制相似问题