2017-07-05 7 views
3

私はnode.jsを初めて使用しています。リクエストを使用してpost.butを送信しましたが、エラーが発生しました。要求は機能しません、エラー:無効なプロトコル:127.0.0.1 :?

 request({ 
     method: 'POST', 
     url: config.api + '/index', 
     body: { 
     name: "name" 
     }, 
     json: true 
     }) 

     throw er; // Unhandled 'error' event 
     ^

     Error: Invalid protocol: 127.0.0.1: 
+3

URLに「http://」接頭辞がありませんか? 'config.api'の値は何ですか? –

+0

ありがとうございます、私は** http:// **を忘れています。どうもありがとうございました –

答えて

2

私は次のように書いています。これはうまく動作します。このように変更できます。

 request({ 
      method: 'POST', 
      url: 'http://127.0.0.1:3000' + '/index', 
      body: { 
      name: "name" 
      }, 
      json: true 
      }) 
関連する問題