简体   繁体   English

如何设置基本身份验证、内容类型和数据以在 axios 发布请求中发送?

[英]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.posturl之后需要一个正文:

axios.post(url, body, options);

Passing null or and empty object should solve it.传递null或空对象应该可以解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Axios POST 请求:内容类型已设置,但在 spring 内部为空 - Axios POST request: Content-type is set, but inside spring it's empty axios 发布请求正在发送请求 header 的 Content-Type: multipart/form-data 导致未定义的 req.body - axios post request is sending a request header of Content-Type: multipart/form-data resulting in undefined req.body 使用字符串作为请求正文时,为什么 Axios 发送我的 POST 请求时使用 Content-Type application/x-www-form-urlencoded? - Why does Axios send my POST request with Content-Type application/x-www-form-urlencoded when using a string as the request body? 如何为backbone.js设置内容类型和POST? - How to set content-type and POST for backbone.js? 使用POST设置请求标头的内容类型 - setting the request header content-type with POST 在 axios 请求 Javascript 中从 Content-type/html 转换为 Json - Converting from Content-type/html to Json in axios request Javascript 反应,axios,内容类型 - React, axios, content-type AngularJS无法使用Content-Type:application / json发送post请求 - AngularJS can't send post request with Content-Type:application/json 在axios中设置Content-Type标头会导致没有数据发送 - Setting Content-Type header in axios causes no data is sent 节点/请求错误:“处理POST请求:无内容类型” - Node/Request Error: “Processing POST Request: No Content-Type”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM