简体   繁体   English

http标头响应400

[英]http header response 400

Hi I try to consume api rest But I can not send the header correctly I have an error 400 that tells me that the body of the request is not valid, it has been treated in many ways and I think the problem is the header. 嗨,我尝试使用api rest,但是我无法正确发送标头,但我收到一个错误400,该错误告诉我请求的主体无效,已通过多种方式对其进行了处理,我认为问题是标头。 they ask me to send the Public-Merchant-Id in the headers y try this: 他们要求我在标头中发送Public-Merchant-Id,请尝试以下操作:

KushkiS: function(card,cvc,total) {
            console.log(card,cvc,total);
            var deferred = $q.defer();
            var req = {
             method: 'POST',
             url: 'https://api-uat.kushkipagos.com/v1/tokens',
             headers: {
               'Authorization': 'Public-Merchant-Id:1000000243'
             },
             request: {
                  "card": {
                    "name": card.data.nombre,
                    "number": card.data.number.toString(),
                    "expiryMonth": "02",
                    "expiryYear": "21",
                    "cvv": cvc
                  },
                  "totalAmount": total,
                  "currency": "USD",
                  "isDeferred": false
                }

            };
            $http(req).then(function(responseData){
                console.log(responseData);
                deferred.resolve(responseData);

            }, function(error){
                console.log(error);
                alert(JSON.stringify(error));
                deferred.reject(error);
            }); 

The information of the api contains this: api的信息包含以下内容:

Public-Merchant-Id header string Public-Merchant-Id标头字符串

request body 请求主体

{
  "card": {
    "name": "Lisbeth Salander",
    "number": "4242424242424242",
    "expiryMonth": "02",
    "expiryYear": "21",
    "cvv": "123"
  },
  "currency": "USD"
}

Looks like you missing content type , you can pass headers using config object. 看起来您缺少content type ,可以使用config对象传递headers

   var data = {};

   var config = {
      headers : {
         'Content-Type': 'application/json',
         'Authorization': 'Public-Merchant-Id:1000000243'

      }
    }

    $http.post(url, data, config).success(function (data, status, headers, config) {
        //do something
     }).error(function (data, status, header, config) {
        //do something
     });

Looks like the service is expecting 'Public-Merchant-Id' header but you are passing 'Authorization' header. 看起来该服务期望使用“ Public-Merchant-Id”标头,但您正在传递“ Authorization”标头。

headers: {  'Public-Merchant-Id':'1000000243' }

Contact with your service provider or go through the Api documentation to get details about how to use them correctly. 请与您的服务提供商联系或浏览Api文档以获取有关如何正确使用它们的详细信息。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM