进行了http请求,post怎么form表单? 有人知道吗

48 阅读1分钟

const objectToQueryString = (params: object) => { let result = "" for (let key in params) { const value = params[key] result += `key={key}={value}&` } result = result.slice(0, -1) return result } const POST = (url: string, params?: object, header?: object): Promise => { return http.createHttp() .request(url, { method: http.RequestMethod.POST, extraData: objectToQueryString(params), header: { ...(header || {}), 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', }, }) .then(res => { return res.result.toString() }) } POST("www.wanandroid.com/user/login", {username: "zhuliyao", password: "zhuliyao123"}) .then((res) => { console.log(res) })