【发布时间】:2020-08-05 17:20:21
【问题描述】:
我在经典的 web apis 中做过几次,但在 Azure Functions 中没有,所以我不确定我在这里缺少什么:
我的实体用户:
[SharedCosmosCollection("shared")]
public class User : ISharedCosmosEntity
{
/// <summary>
/// User id
/// </summary>
[JsonProperty("Id")]
public string Id { get; set; }
/// <summary>
/// Cosmos entity name for shared collection
/// </summary>
[CosmosPartitionKey]
public string CosmosEntityName { get; set; }
public string GivenName { get; set; }
public string FamilyName { get; set; }
public string NickName { get; set; }
public string Name { get; set; }
public string Picture { get; set; }
public string Locale { get; set; }
public DateTime UodatedAt { get; set; }
public string Email { get; set; }
public bool EmailVerified { get; set; }
public string Sub { get; set; }
}
我的 CreateUser 函数代码:
[FunctionName("CreateUser")]
public static async Task<IActionResult> CreateUser(
[HttpTrigger(AuthorizationLevel.Function,
"post", Route = "user")]
HttpRequest req)
{
var telemetry = new TelemetryClient();
try
{
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var input = JsonConvert.DeserializeObject<User>(requestBody);
var userStore = CosmosStoreHolder.Instance.CosmosStoreUsers;
var added = await userStore.AddAsync(input);
return new OkObjectResult(added);
}
catch (Exception ex)
{
string guid = Guid.NewGuid().ToString();
var dt = new Dictionary<string, string>
{
{ "Error Lulo: ", guid }
};
telemetry.TrackException(ex, dt);
return new BadRequestResult();
}
}
在门户中,我在请求正文中发送此 JSON
{
"given_name": "aaa",
"family_name": "bbb",
"nickname": "xx.xx.psg",
"name": "bbbb",
"picture": "https://lh3.googleusercontent.com/a-/AOhsGg8qaBLDPubSaNb3u8zMyiUGrwFE3zhQ8MMqLALjGc",
"locale": "es",
"updated_at": "2020-04-20T15:33:16.133Z",
"email": "xx.xx.psg@gmail.com",
"email_verified": true,
"sub": "google-oauth2|1111"
}
但是我收到 http 500 错误,但不确定是什么问题
【问题讨论】:
标签: c# .net azure asp.net-core azure-functions