如何解决如何在多部分请求的放置请求中设置参数化内容类型
我在使用 application/json 内容类型在表单数据中传递 requestDTO 对象时遇到问题。
我使用 Dio 库使用了以下代码。但在 Dio 参数值作为字符串传递。我从服务器中丢失 requestDTO 对象错误。
Map<String,String> header = Map<String,String>();
header['Authorization'] = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI4NzY1NDMyMTA5IiwiYXV0aCI6IlJPTEVfQ09OVFJBQ1RPUiIsImV4cCI6MTYxNTYzNjIxMX0._pBVg6aWSl2K2bf416w1YnxYpQeEckL1Go9b_TRgaVruwcyh7tB5OdY9ujSiORn3rVpE39kPIX5zTTuwSJC3lQ';
header['content-type'] = 'multipart/form-data';
Map<String,dynamic> params = Map<String,dynamic>();
params['requestDTO'] = '{\n "email": "c1@yopmail.com",\n "firstName": "Contractor",\n "fullName": "Contractor",\n "imageUrl": "string",\n "lastName": "two",\n "phoneNumber": "8765432109",\n "prAddressDTO": {\n "addressLine": "string",\n "city": "string",\n "country": "string",\n "id": 7009,\n "latitude": 0,\n "longitude": 0,\n "prUserId": 6104,\n "state": "string",\n "zipcode": "string"\n },\n "prBusinessInfoDTO": {\n "businessLicense": "string",\n "businessName": "string",\n "experience": 0,\n "id": 6251,\n "liabilityInsurance": "string",\n "noOfWorkers": 0,\n "notes": "string",\n "projectsCompleted": 0,\n "servicesCategory": "string",\n "servicesSubCategory": "string",\n "stateRegistration": "string",\n "taxIdentificationNumber": "string"\n },\n "userType": "CONTRACTOR"\n}';
// Create form data Request
FormData formData = new FormData.fromMap(params);
final option = Options(headers: header);
try {
final response = await this.dio.put('http://180.211.99.164:9091/api/contractor/me',data: formData,options: option,onSendProgress: (sent,total) => Logger().v("uploadFile ${sent / total}"));
this._handleNetworkSuccess(response: response);
} on DioError catch (error) {
this._handleDioNetworkError(error: error);
}
解决方法
请检查这个答案https://stackoverflow.com/a/65737169/13439617
它发送请求时没有 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="quantity quantitym2">
<label class="screen-reader-text" for="quantity_60269d6f09cd1">Boost quantity</label>
<input type="number" onchange="myFunctionupdateqtyinput()" id="quantity_60269d6f09cd1" class="input-text qty text" value="3.336" step="0.0001" min="0.0001" max="" name="quantity" title="title" size="4" placeholder="" inputmode="">
</div>
<div class="kpt-product-count" data-kptcount="10">
<div class='kpt-product-count-label'>In total: </div>
<div class='kpt-product-count-text'> <span>10</span> </div>
</div>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。