FormData.contentType 用于获取 form-data 的 ContentType 字段。
contentType(): string
返回
类型 | 描述 |
string | ContentType 字段值 |
样例
import http from 'pts/http';const data = open('./sample/tmp.js');export default function () {const formData = new http.FormData();formData.append('text', 'text');formData.append('file', http.file(data, 'tmp.js'));// 返回 "multipart/form-data; boundary=xxxxxx"console.log(formData.contentType());const resp = http.post('http://mockhttpbin.pts.svc.cluster.local/post', formData.body(), {headers: {'Content-Type': formData.contentType()}});console.log('formData: ', resp.body);};