Chrome REST控制台"连接失败!"

时间:2014-06-07 17:58:04

标签: google-chrome asp.net-web-api

我有一个简单的测试Web API,它正常运行。当我运行它并在浏览器中输入http://localhost:xxxxx/api/user时,它返回一个JSON空数组,当我用Fiddler测试它时它具有完整的功能。但是,当我尝试使用Chrome REST控制台(向http://localhost:xxxxx/api/user发送GET请求)进行测试时,我收到“连接失败!检查连接并重试”错误。

Api控制器:

public class UserController : ApiController
{     
  private UserRepository repository = new UserRepository();

  public int Put(int id, [FromBody]int amount)
  { 
     var user = repository.GetByID(id);
     if (user == null) return -1;
     user.Total += amount;
     repository.Save(user);
     return user.Total;
   }

  public int Post([FromBody]CreateUserRequest request)
  { 
    var user = new User { Goal = request.Goal, Name = request.Name, Total = 0 };
    repository.Add(user);
    return user.UserId;
  }

  public IEnumerable<User> Get() { return new List<User>(repository.GetAll()); }

  public User Get(int id) {  var user = repository.GetByID(id); return user; }

  public class CreateUserRequest
  {
    public string Name { get; set; }
    public int Goal { get; set; }
  }

REST控制台之前曾使用过此测试Web API。我在网上找到的唯一引用引用了未签名的证书。我在IIS中为localhost创建了一个签名证书但我删除了它,重新启动了计算机,REST控制台仍然返回相同的错误。这并不重要,因为Web API在IIS Express中运行。我也在我的本地机器上尝试了其他Web API并得到了同样的错误。

有没有人知道问题的可能来源或我如何解决问题?正如我所说,在使用Fiddler进行测试时,Web API完全正常运行。 Web API是在Windows 7 Ultimate工作站上使用VS 2012创建的,并且正在运行。

1 个答案:

答案 0 :(得分:0)

我后来注意到,当我从Chrome中的Visual Studio运行应用程序时,它会重定向到https(即使是未使用SSL的应用程序)并生成SSL错误。

我清除了Chrome中的所有浏览数据,并清除了Chrome和REST控制台问题。