首页 > 解决方案 > URL 参数作为 null 传递,而不是预期传递的参数

问题描述

我观看了有关创建我的第一个 DynamoDb 的视频以及他的 github 代码。我在数据库中添加了三个字段,标题、创建者和正文。当我在 GET url 中将它们传递为

https://localhost:44317/api/dynamodb/putitems?id=4&replyDateTime=63668789020007900&body=ilovelife&title=mytittle&creator=me

它被放置在数据库中:

        {
            "id": 4,
            "replyDateTime": "63668789020007900",
            "body": null,
            "title": null,
            "creator": null
        },

这是我添加字段的 C# 代码:

private PutItemRequest RequestBuilder(int id, string replyDateTime, string body, string title, string creator)
        {
            var item = new Dictionary<string, AttributeValue>
            {
                {"Id", new AttributeValue {N = id.ToString()}},
                {"ReplyDateTime", new AttributeValue {N = replyDateTime}},
                {"Body", new AttributeValue {S = body}},
                 {"Creator", new AttributeValue {S = creator}},
                  {"Title", new AttributeValue {S = title}}
            };

            return new PutItemRequest
            {
                TableName = "BlogDynamoDbTable",
                Item = item
            };

Item 中的值被发送到数据库但最终为空:

在此处输入图像描述

标签: apiamazon-dynamodb

解决方案


我将 API 代码更改为 POST 而不是 GET。在为 NET 3.0 添加另一个用于读取 json 的 nuget 包后,JSON 数据有效


推荐阅读