我在使用某些代码时遇到了问题,而且我似乎无法弄清楚这一点。我正在尝试将一些数据发送到连接到我们的 SQL Server 的后端 API,并执行一个我不希望得到任何结果的查询。我遇到的问题是 SQL 命令没有发送到服务器,并且我收到“404 - 此文件不存在”。
这是请求的前半部分:
public async Task ExportNewLists (string pid, string list)
{
var endpointUrl = string.Concat(baseEndpoint, "ExportLists", "/", pid, "/", list);
AddAuthorization();
using (HttpResponseMessage response = await client.GetAsync(endpointUrl))
{
if (!response.IsSuccessStatusCode)
{
Response.StatusCode = (int)response.StatusCode;
var result = response.Content.ReadAsStringAsync().Result;
var message = JsonConvert.DeserializeObject<ResponseError>(result);
}
}
}
这是我尝试调用的 API 函数:
[Route("api/Lists/ExportLists/{pid}/{list}")]
[HttpGet]
[ResponseType(typeof(void))]
private async Task<IHttpActionResult> ExportList(string pid, string list)
{
using (var connection = db.Database.Connection)
{
try
{
connection.Open();
var command = connection.CreateCommand();
command.Connection = connection;
command.CommandText = "EXEC LIST_EXPORT_SINGLE";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@PID");
command.Parameters["@PID"].Value = pid;
command.Parameters.Add("@LIST");
command.Parameters["@LIST"].Value = list;
await command.ExecuteNonQueryAsync();
connection.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
return Ok();
}
您已将 ExportScrubList 标记为私有。您无法通过 http 调用标记为私有的操作。