gpt4 book ai didi

c# - 无法通过 fiddler 发布新记录

转载 作者:太空宇宙 更新时间:2023-11-03 23:25:13 25 4
gpt4 key购买 nike

我现在在通过 fiddler 发布记录时遇到了问题。我的代码如下:

[HttpPost]
public void AddStudent(Student s)
{
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = @"Data Source=PALLAVI-PC\SQLEXPRESS;Initial Catalog=StudentDB;Integrated Security=True;MultipleActiveResultSets=True;";

SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandType = CommandType.Text;
sqlCmd.CommandText = "INSERT INTO Tbl_Students (Roll_Number,FirstName,LastName,Class,Gender) Values (@Roll_Number,@FirstName,@LastName,@Class,@Gender)";
sqlCmd.Connection = myConnection;

sqlCmd.Parameters.AddWithValue("@Roll_Number", s.Roll_Number);
sqlCmd.Parameters.AddWithValue("@FirstName", s.FirstName);
sqlCmd.Parameters.AddWithValue("@LastName", s.LastName);
sqlCmd.Parameters.AddWithValue("@Class", s.Class);
sqlCmd.Parameters.AddWithValue("@Gender", s.Gender);

myConnection.Open();
int rowInserted = sqlCmd.ExecuteNonQuery();
myConnection.Close();
}

当我在 fiddler 上运行它时,我得到一个 NullException。代码不排除响应主体。响应正文为 JSON 格式。图片如下:

enter image description here

编辑这是我遇到的错误(图片)。

enter image description here

最佳答案

我也会在 Fiddler 中设置 Content-Type header

内容类型:application/json

关于c# - 无法通过 fiddler 发布新记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34025535/

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