2016-05-04 11 views
0

私はAPIを使用してjsonからPDFを作成しています。Error 400 AngularJSでAPIを使用

私は$http angularjsサービスを使用していますが、リクエストするとHTTP 400エラーコードが表示されます。

これはコードです。

angular.module('instantPDFApp', []) 
.controller('mainController', ['$http', function ($http){ 
    $http.post("https://yogthos.p.mashape.com/", '[{}, ["paragraph", "some text"]]' ,{ 
     headers : { 
      'Content-Type' : 'application/json', 
      'X-Mashape-Key' : 'MXQJRkqiLumshE4GCKbhIvtR3ytvp19hpZxjsn2vSk4L5dXrE4' 
     } 
    }).then(
     function (response) { 
      document.write(response.data); 
     }, 

     function() { 
      console.error("Error"); 
     } 
    ); 
}]); 

答えて

0

これはサーバーの応答です(要求が不正です)。完全なリクエストを角度で使用してみてください。たとえば :あなたがここに見つけることができますリクエストデータの

$http({ 
    method: 'GET', 
    url: '/someUrl', 
    params: { 
     param1: 'hello' 
    }, 
    headers: { 
     'Content-Type' : 'application/json' 
    } 
}).then(function successCallback(response) { 
    // this callback will be called asynchronously 
    // when the response is available 
}, function errorCallback(response) { 
    // called asynchronously if an error occurs 
    // or server returns response with an error status. 
}); 

全リスト:https://docs.angularjs.org/api/ng/service/ $ HTTP#用法

は、それはあなたを助けることを願っています。

関連する問題