我有一个WP7游戏,它使用RESTsharp与我的MVC4 RESTful服务器通信,但我经常在发出有效的请求时遇到问题,因此我想在失败的地方进行调试.

这是一个例子,我的GameController上的构造函数被命中,但Post方法没有命中,我不明白为什么.

客户端代码:

public void JoinRandomGame()
{
  client = new RestClient
  {
      CookieContainer = new CookieContainer(),
      BaseUrl = "http://localhost:21688/api/",
  };

  client.Authenticator = GetAuth();

  RestRequest request = new RestRequest(Method.POST)
  {
      RequestFormat = DataFormat.Json,
      Resource = "game/"

  };

  client.PostAsync(request, (response, ds) =>
  {});
}

服务器代码:

    public void Post(int id)
    {
        if (ControllerContext.Request.Headers.Authorization == null)
        {
            //No auth
        }
        if (!loginManager.VerifyLogin(ControllerContext.Request.Headers.Authorization.Parameter))
        {
            //Failed login
        }

        string username;
        string password;
        LoginManager.DecodeBase64(ControllerContext.Request.Headers.Authorization.Parameter, out username, out password);
        gameManager.JoinRandomGame(username);
    }

我的路由是这样的

       routes.MapHttpRoute(
            name: "gameAPI",
            routeTemplate: "api/game/{gameId}",
            defaults: new
            {
                controller = "game",
                gameId = RouteParameter.Optional
            }             
        );

推荐答案

RouteDebugger很适合计算哪些路由将/不会被命中.

http://nuget.org/packages/routedebugger

.net相关问答推荐

ASP.NET核心最小API必须以正斜杠开头吗?

如何通过在后台预加载流项来优化流迭代的性能?

如何手动注入依赖注入

FileHelpers 未使用正确的日期格式

如何在 NET 5 / 6 中使用 Direct3D11CaptureFramePool

使用 SSH.NET 查找具有特定文件名的最新 SFTP 文件

将日期时间转换为日期格式 dd/mm/yyyy

在 C# 中将字符串转换为 colored颜色

在 C# DllImport 中使用 32 位或 64 位 dll

.NET 世界是否有 Maven 替代方案或端口?

什么决定了 Path.GetTempPath() 的返回值?

你如何调试 MVC 4 API 路由?

如何遍历字典并更改值?

加载程序集、查找类和调用 Run() 方法的正确方法

从 OpenFileDialog 路径/文件名中提取路径

将日期时间转换为时间跨度

如何找到二维数组的大小?

如何判断uri字符串是否有效

Windows 服务在哪个目录中运行?

为 webClient.DownloadFile() 设置超时