[英]c# REST service Post will not respond?
我有一个C#解决方案,其中有一个REST服务项目,该项目使用另一个类库项目。 如果我发送GET请求,则服务正确响应。 但是,如果我发送POST ,则该服务的Post实现可以正确地在数据库中插入数据。 但是,我在客户端(Fiddler)没有收到响应状态代码( 200 OK )。 在下面,您将找到代码。 提前感谢你的帮助。
using System.Collections.Generic;
using System.Web.Http;
namespace OwinSelfhostSample
{
public class ValuesController : ApiController
{
DatabaseConnector2.DatabaseLibrary database;
// POST api/values
public void Post(Command command)
{
//create connection object and insert data
database = new DatabaseConnector2.DatabaseLibrary(command.Instruction, command.Cell);
}
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
}
Post资源调用以下类:
using System;
using System.Data.SQLite;
namespace DatabaseConnector2
{
public class DatabaseLibrary
{
// Holds our connection with the database
SQLiteConnection m_dbConnection;
Data_connection dbobject;
// Only for testing
//static void Main(string[] args)
//{
// DatabaseLibrary p = new DatabaseLibrary("hola", "chao");
//}
public DatabaseLibrary(string instr, string cell)
{
//createNewDatabase();
connectToDatabase();
//createTable();
insertDataInTable(instr, cell);
printRecords();
}
...
}
}
我在代码中找到了该错误。 我基本上在代码Console.ReadLine();
的末尾有一行Console.ReadLine();
这导致Post资源无法完成。 感谢大家 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.