get

  1. request({
  2. timeout:5000, // 设置超时
  3. method:'GET', //请求方式
  4. url:'xxx', //url
  5. qs:{ //参数,注意get和post的参数设置不一样
  6. xx:"xxx",
  7. xxx:"xxx",
  8. xxx:"xxx"
  9. }
  10. },function (error, response, body) {
  11. if (!error && response.statusCode == 200) {
  12. console.log(body);
  13. }else{
  14. console.log("error");
  15. }
  16. });

post

form

  1. request({
  2. timeout:5000, // 设置超时
  3. method:'GET', //请求方式
  4. url:'xxx', //url
  5. form:{ //参数,注意get和post的参数设置不一样
  6. xx:"xxx",
  7. xxx:"xxx",
  8. xxx:"xxx"
  9. }
  10. },function (error, response, body) {
  11. if (!error && response.statusCode == 200) {
  12. console.log(body);
  13. }else{
  14. console.log("error");
  15. }
  16. });

formData

  1. request({
  2. method : 'POST',
  3. url : 'your url',
  4. headers : {
  5. 'Content-Type' : 'multipart/form-data'
  6. },
  7. formData : {
  8. audio : xxxx
  9. }
  10. }, function (error, response, body) {
  11. if (!error) {
  12. resolve({response, body});
  13. } else {
  14. reject(error);
  15. }
  16. });