Установите заголовки в запросе POST, используя ax ios в реагирующем - PullRequest
0 голосов
/ 06 февраля 2020

Я сталкиваюсь со странной проблемой в реактивном родном использовании axe ios У меня есть один концентратор, в котором мне нужно сделать пост-запрос на регистрацию шайбы, когда я пытаюсь с Postman, он работает отлично, но когда я пытаюсь с симулятора Ipad, он выбрасывает меня этот ответ:

{"data":{"jsonrpc":"2.0","id":"27316","error":{"code":1,"message":"Missing PLSType field","data":null}},"status":200,"headers":{"plsversion":"20190607","content-type":"application/json","server":"akka-http/10.1.8","plstype":"64","plsname":"ThinkinMiddleware","date":"Thu, 06 Feb 2020 11:01:19 GMT","content-length":"95"},"config":{"url":"http://192.168.20.229:8383","method":"post","data":"{\"jsonrpc\":\"2.0\",\"id\":\"27316\",\"method\":\"crManagementExtension\",\"params\":{\"mode\":1,\"puck\":{\"id\":\"DBC0000000fa\",\"number\":13}}}","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","PLSType":32,"PLSName":"cash-559892","PLSVersion":"1.2.3.4"},"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1},"request":{"UNSENT":0,"OPENED":1,"HEADERS_RECEIVED":2,"LOADING":3,"DONE":4,"readyState":4,"status":200,"timeout":0,"withCredentials":true,"upload":{},"_aborted":false,"_hasError":false,"_method":"POST","_response":"{\"jsonrpc\":\"2.0\",\"id\":\"27316\",\"error\":{\"code\":1,\"message\":\"Missing PLSType field\",\"data\":null}}","_url":"http://192.168.20.229:8383","_timedOut":false,"_trackingName":"unknown","_incrementalEvents":false,"responseHeaders":{"PLSVersion":"20190607","Content-Type":"application/json","Server":"akka-http/10.1.8","PLSType":"64","PLSName":"ThinkinMiddleware","Date":"Thu, 06 Feb 2020 11:01:19 GMT","Content-Length":"95"},"_requestId":null,"_headers":{"accept":"application/json, text/plain, */*","content-type":"application/json","plstype":"32","plsname":"cash-559892","plsversion":"1.2.3.4"},"_responseType":"","_sent":true,"_lowerCaseResponseHeaders":{"plsversion":"20190607","content-type":"application/json","server":"akka-http/10.1.8","plstype":"64","plsname":"ThinkinMiddleware","date":"Thu, 06 Feb 2020 11:01:19 GMT","content-length":"95"},"_subscriptions":[],"responseURL":"http://192.168.20.229:8383/"}}

, что я вижу в этом журнале, это то, что поле PLSType отсутствует, что означает, что заголовок PLSType не установлен.

, но когда я пытаюсь с почтальоном, я получаю это Ответ:

{
    "jsonrpc": "2.0",
    "id": 1234,
    "result": {
        "status": 10,
        "puck": {
            "battery": 100,
            "colors": null,
            "location": null
        }
    }
}

, и эта функция выполняется:

axios.post(
          "http://192.168.20.229:8383",
          {
            jsonrpc: "2.0",
            id: "27316",
            method: "crManagementExtension",
            params: {mode: 1, puck: {id: "DBC0000000fa", number: 13}},
          },
          {
            headers: {
             "Content-Type": "application/json",
             PLSType: 32,
             PLSName: "cash-559892",
             PLSVersion: "1.2.3.4",
            }
          },

        ).then(response => {
          console.log('response sukses')
          console.log(JSON.stringify(response));
          // return resolve(response);
        })
        .catch(error => {
            console.log('error while registering puck sukses')
          console.log(error);
          // reject(error);
        });

Я попробовал точно такую ​​же функцию в React JS, и она работает.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...