- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
Dart http package的 post
方法只接受 String
, 一个 List<int>
或 Map<String, String>
作为请求正文。我需要使用 Content-Type header application/json 发送此类的对象作为正文:
class CreateListingRequest {
String title;
List<ListingImage> images;
List<int> categoryIds;
}
哪里ListingImage
是
class ListingImage {
String url;
int position;
}
在 Postman 中,我会将正文构建为带有 Content-Type header 的原始 json application/json
像这样:
{
"title": "Testing transaction force fail",
"listing_images": [
{
"url": "https://picsum.photos/500/500/?image=336",
"position": 0
},
{
"url": "https://picsum.photos/500/500/?image=68",
"position": 1
},
{
"url": "https://picsum.photos/500/500/?image=175",
"position": 2
}
],
"category_ids": [19, 26]
}
在我看来,如果我可以发送 Map<String, dynamic>
那会解决问题,但我只能发送 Map<String, String>
.
请帮忙。
最佳答案
使用 String encoded = json.encode(theMap);
然后发布encoded
.如果您需要特定的字符编码(例如 utf-8),则使用 utf8.encode(encoded)
进一步对字符串进行编码并发布生成的字节数组。 (第二步对于 utf-8 应该是不必要的,因为我认为这是默认设置。)
值得考虑这 3 个变体的作用:
List<int>
- 发送一个不透明的字节数组String
编码使用字符编码将字符串转换为字节 - 并发送字节数组Map<String, String>
- 对 x-www-form-urlencoded
中的字符串键/值对进行编码并发送。如果你想发送更复杂的数据,那么你需要将它转换成上述之一(并且服务器需要知道如何解码它)。那就是 content-type
的地方标题很有用。最终,服务器接收到一个字节数组并将其转换回例如一个字符串,或一些 json,或一组表单字段,或一张图像。它知道如何根据 header 和任何指定的编码来执行此操作。
关于json - 以 Map<String, dynamic> 作为正文的 Dart HTTP POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54598879/
如何将多个json对象添加/映射到dart对象 import 'dart:async'; import 'dart:convert'; import 'package:flutter/foundati
我正在研究将产品集成到 Dynamics Great Plains 中。我之前使用过 Dynamics CRM,但没有使用过 Great Plains。我听说 GP 与 CRM 是不同的动物,即使它们
System.Linq.Dynamic.Core 和 System.Linq.Dynamic 有什么区别?我目前正在使用 System.Linq.Dynamic 并且它不包含对 的支持选择 和 多选
我正在尝试通过Firebase存储将图像上传到Firebase,然后在Firestore中创建一个文档,其中包含上述上传图像的网址。为此,我使用此功能 void uploadImageAndCr
我一直在尝试整理一些东西,使我可以从 ListPlot 中提取点,以便在进一步的计算中使用它们。我目前的方法是使用 Locator[] 选择点。这适用于显示点,但我无法弄清楚如何从带有 head Dy
只要我在与 Program 类相同的程序集中有类 ClassSameAssembly ,下面的代码就可以正常工作。但是,当我将类 ClassSameAssembly 移动到单独的程序集时,会引发 Ru
我只是尝试从Firebase实时数据库解析数据。 但在转换为模型时有问题 我正在尝试从Flutter上解析Firebase数据库中的数据。 但是一个错误说 MY Complete QUIZ: {-M5
我创建了一个方法,当我构建它时,出现了这个错误: type '_InternalLinkedHashMap' is not a subtype of type 'List' in type cast
我对这个 flutter 的简单图表代码有疑问。在我尝试运行代码时显示此错误。请任何人都可以帮助我在这.... The argument type 'List>' can't be assigned
我尝试在我的 flutter 应用程序中解析来自 Firestore 的文档。 Firestore 文档: 我创建了两个类来解析这个文档。 类产品: class Produkt{ String n
我有一个2d-List,其中包含一个字符串和一个Map,如下所示: List> content = [ [ "String", { "one": 23,
我使用 Dart“json_serializable”包在 Flutter 应用程序中的 Firestore 数据结构下反序列化。 { googleBookId: jjl4BgAAQBAJ, prov
我注册了 Dynamic CRM 在线试用版(30 天)并创建了一个非托管自定义解决方案(新字段、一些自定义实体等)。现在,我想导出非托管解决方案并将其导入到我的服务器中的 Dynamic CRM O
当我尝试从 StreamTransform 获取一些数据时遇到一些问题 我不明白什么是正确的数据类型 未捕获的异常:类型错误:“_StreamHandlerTransformer”的实例:“_Stre
我正在尝试获取用户数据,但在这样做时出现以下错误: Exception: type '_InternalLinkedHashMap' is not a subtype of type 'Map 我查看
我正在尝试在 sqflite 数据库中保存一些带有 flutter 的数据,但我仍然收到一条错误消息: [ERROR:flutter/shell/common/shell.cc(181)] Dart
我有一个JSON响应,结构如下:。在这个JSON响应中,有各种动态键,如“Owner”和“Master”,每个键都包含一个JSON对象或一个JSON对象数组。我需要创建一个gson数据类来解析这个动态
在 Dynamics 2012 ax 中编译 CIL 时,我看到以下错误 - 名称为“Dynamics.Ax.application”的重复类型。在程序集中“Dynamics.Ax.applicati
我有一个带有 LinkedHashMap 成员的 StatefulWidget 小部件,如下所示: LinkedHashMap _items = new LinkedHashMap>(); 现在我需要
我正在尝试按照此处所述实现搜索资源功能:https://cloudblogs.microsoft.com/dynamics365/it/2019/05/21/retrieve-resource-ava
我是一名优秀的程序员,十分优秀!