2017-10-25 4 views
1

私のReact Nativeプロジェクトからoauth/tokensを使用してログインしようとしています。私はPOSTMANでテストしました。私がAxiosからデータを送信するとうまくいきます。私は私のアプリから送信しようとすると、しかし、それは私にエラーを与える:ステータスコードで失敗した要求400 私のコードは次のとおりです。lactvelパスポートを使用してoauth/tokenに投稿するとネイティブ応答400が返される

axios({ 
method: 'post', 
url: 'http://183.172.100.84:8000/oauth/token', 
headers: { 
    'Accept': 'application/json', 
     'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' 
}, 
data: { 
    client_id : '2', 
    client_secret : 'secret', 
    grant_type : 'password', 
    email : this.state.userEmail, 
    password : this.state.userPassword 
} 
}) 
.then((response) => { 
console.log(response.data); 
}) 
+0

Telerik fiddlerのようなスニファを使用して、データが正しく形成されていることを確認してください。 –

答えて

0

私はこの方法で問題を解決しました:

axios({ 
method: 'post', 
url: 'http://183.172.100.84:8000/oauth/token', 
headers: { 
    'Accept': 'application/json', 
     'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' 
}, 
data: 'client_id=2&client_secret=secret&grant_type=password&email=' + this.state.userEmail+'&password='+this.state.userPassword  
}) 
.then((response) => { 
console.log(response.data); 
}) 

Axiosはjson形式でデータを処理するには問題があります。

関連する問題