[英]How to set basic auth, content-type and data to send in axios post request?
I'm a beginner with React Native and I'm trying to send data to IBM speech to text conversion Api with axios.我是 React Native 的初学者,我正在尝试使用 axios 将数据发送到 IBM 语音到文本转换 Api。 I'm getting the response in Postman but I can't set my data in axios request.我在 Postman 中收到响应,但无法在 axios 请求中设置我的数据。 The request needed basic auth, content-type and file (data).请求需要基本身份验证、内容类型和文件(数据)。 How to set all of this in axios request?如何在 axios 请求中设置所有这些? I'm getting a status code of 415 This is the code Picture .我得到 415 的状态代码这是代码 Picture 。
axios .post( IBMURL, { withCredentials: true, headers: { 'Content-Type': 'audio/mp3', }, }, { auth: { username: 'apikey', password: ApiPassword, }, }, ) .then((response) => { console.log('Reponse', response.data); }) .catch((e) => console.log(e));
axios.post
requires a body after the url
: axios.post
在url
之后需要一个正文:
axios.post(url, body, options);
Passing null
or and empty object should solve it.传递null
或空对象应该可以解决它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.