Azure 移动服务 - 使用具有复杂类型参数的 POST 操作

标签 azure azure-mobile-services

我使用以下方法创建了一个自定义 Controller :

// POST api/CustomLogin
public HtpResponseMessage Post(LoginRequest loginRequest)
{
     // ...
}

登录请求在哪里:

public class LoginRequest
{
    public string Username { get; set; }
    public string Password { get; set; }
}

如何使用 Microsoft.WindowsAzure.MobileServices.MobileServiceClient 来使用此操作?我本来希望使用 InvokeApiAsync,但我只能看到两个覆盖,这两个覆盖都不允许我在请求消息中传递内容。

最佳答案

您应该能够执行以下操作:

var loginParams = new LoginRequest() { ... };
var result = await Client.invokeApiAsync<LoginResult, string>("CustomLogin", loginParams);

其中任何一个都将为您提供控制请求内容的选项,第一个选项为您提供对内容和响应的完全控制。

public async Task<HttpResponseMessage> InvokeApiAsync(string apiName, 
  HttpContent content, HttpMethod method, IDictionary<string, string> 
  requestHeaders, IDictionary<string, string> parameters)

public async Task<U> InvokeApiAsync<T, U>(string apiName, T body, 
  HttpMethod method, IDictionary<string, string> parameters)

public async Task<JToken> InvokeApiAsync(string apiName, JToken body,    
  HttpMethod method, IDictionary<string, string> parameters)

关于Azure 移动服务 - 使用具有复杂类型参数的 POST 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29383524/

相关文章:

c# - 在 Windows 8 商店应用程序中显示 Azure 移动服务数据库中表中的所有记录 - C#

javascript - 如何在 Azure 表存储中查找与值数组不匹配的记录?

java - 带有 Android 的 Azure 移动服务

azure - 如果 IoT 中心重新启动,设备是否会重新连接?

python - 无法使用 VSCODE Python 将基本示例 HttpRequest1 部署到 Azure Function

azure - Docker 上的端口

azure - 如何获取应用程序服务环境ID以在terraform中的应用程序服务计划中使用

azure - 如何使用 IMobileServiceSyncTable 访问 IncludeTotalCount 返回的数据?

Azure数据工厂: complex (JSON) state management

javascript - 在 Azure 移动服务 Javascript SDK 中使用 $expand 查询