我在一些代码上遇到了问题,我似乎就是想不通。我正在尝试将一些数据发送到后端API,该API连接到我们的SQL Server并执行一个查询,而我并不希望得到任何类型的结果。我遇到的问题是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();
}
发布于 2017-07-31 22:14:12
您已将ExportScrubList标记为私有。不能通过http调用标记为私有的操作。
https://stackoverflow.com/questions/45418257
复制相似问题