Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axio post in expo #4776

Open
quantrpeter opened this issue Jun 10, 2022 · 1 comment
Open

Axio post in expo #4776

quantrpeter opened this issue Jun 10, 2022 · 1 comment

Comments

@quantrpeter
Copy link

Hi
I am using Axios 0.27.2 in react native and running it in App Expo. The code called successfull but the result.data is empty. If i move this code to run on my pc, it works.

        const URL = "https://www.xxx.org.hk/tc/quantr/login";

        const params = new URLSearchParams();
        params.append('username', username);
        params.append('password', password);

        const config = {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }

        const axios = require('axios').default;
        const result = await axios.post(URL, params, config);

        console.log(result);
        console.log(result.data.full_name_tc);
        return result;
Object {
  "config": Object {
    "adapter": [Function xhrAdapter],
    "data": FormData {
      "_parts": Array [
        Array [
          undefined,
          URLSearchParams {
            "_searchParams": Array [
              Array [
                "username",
                "peter@quantr.hk",
              ],
              Array [
                "password",
                "xxx",
              ],
            ],
          },
        ],
      ],
    },
    "env": Object {
      "FormData": null,
    },
    "headers": Object {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "multipart/form-data",
    },
    "maxBodyLength": -1,
    "maxContentLength": -1,
    "method": "post",
    "timeout": 0,
    "transformRequest": Array [
      [Function transformRequest],
    ],
    "transformResponse": Array [
      [Function transformResponse],
    ],
    "transitional": Object {
      "clarifyTimeoutError": false,
      "forcedJSONParsing": true,
      "silentJSONParsing": true,
    },
    "url": "https://www.xxx.org.hk/tc/quantr/login",
    "validateStatus": [Function validateStatus],
    "xsrfCookieName": "XSRF-TOKEN",
    "xsrfHeaderName": "X-XSRF-TOKEN",
  },
  "data": "",
  "headers": Object {
    "cache-control": "no-store, no-cache, must-revalidate, post-check=0, pre-check=0",
    "connection": "Keep-Alive",
    "content-type": "application/json; charset=utf-8",
    "date": "Fri, 10 Jun 2022 06:19:32 GMT",
    "expires": "Thu, 19 Nov 1981 08:52:00 GMT",
    "keep-alive": "timeout=5, max=100",
    "pragma": "no-cache",
    "server": "Apache",
    "transfer-encoding": "Identity",
  },
  "request": XMLHttpRequest {
    "DONE": 4,
    "HEADERS_RECEIVED": 2,
    "LOADING": 3,
    "OPENED": 1,
    "UNSENT": 0,
    "_aborted": false,
    "_cachedResponse": undefined,
    "_hasError": false,
    "_headers": Object {
      "accept": "application/json, text/plain, */*",
      "content-type": "multipart/form-data",
    },
    "_incrementalEvents": false,
    "_lowerCaseResponseHeaders": Object {
      "cache-control": "no-store, no-cache, must-revalidate, post-check=0, pre-check=0",
      "connection": "Keep-Alive",
      "content-type": "application/json; charset=utf-8",
      "date": "Fri, 10 Jun 2022 06:19:32 GMT",
      "expires": "Thu, 19 Nov 1981 08:52:00 GMT",
      "keep-alive": "timeout=5, max=100",
      "pragma": "no-cache",
      "server": "Apache",
      "transfer-encoding": "Identity",
    },
    "_method": "POST",
    "_perfKey": "network_XMLHttpRequest_https://www.xxx.org.hk/tc/quantr/login",
    "_performanceLogger": PerformanceLogger {
      "_closed": false,
      "_extras": Object {},
      "_pointExtras": Object {},
      "_points": Object {
        "initializeCore_end": 1654841538885,
        "initializeCore_start": 1654841538863,
      },
      "_timespans": Object {
        "network_XMLHttpRequest_http://172.20.6.112:19000/logs": Object {
          "endExtras": undefined,
          "endTime": 1654841539259,
          "startExtras": undefined,
          "startTime": 1654841539063,
          "totalTime": 196,
        },
        "network_XMLHttpRequest_https://www.xxx.org.hk/tc/quantr/login": Object {
          "endExtras": undefined,
          "endTime": 1654841550245,
          "startExtras": undefined,
          "startTime": 1654841549939,
          "totalTime": 306,
        },
        "network_XMLHttpRequest_https://www.xxx.org.hk/tc/quantr/login?_searchParams[]=[%22username%22,%22ppp%22]&_searchParams[]=[%22password%22,%22xxx%22]": Object {
          "endExtras": undefined,
          "endTime": 1654841847088,
          "startExtras": undefined,
          "startTime": 1654841846783,
          "totalTime": 305,
        },
      },
    },
    "_requestId": null,
    "_response": "",
    "_responseType": "",
    "_sent": true,
    "_subscriptions": Array [],
    "_timedOut": false,
    "_trackingName": "unknown",
    "_url": "https://www.xxx.org.hk/tc/quantr/login",
    "readyState": 4,
    "responseHeaders": Object {
      "Cache-Control": "no-store, no-cache, must-revalidate, post-check=0, pre-check=0",
      "Connection": "Keep-Alive",
      "Content-Type": "application/json; charset=utf-8",
      "Date": "Fri, 10 Jun 2022 06:19:32 GMT",
      "Expires": "Thu, 19 Nov 1981 08:52:00 GMT",
      "Keep-Alive": "timeout=5, max=100",
      "Pragma": "no-cache",
      "Server": "Apache",
      "Transfer-Encoding": "Identity",
    },
    "responseURL": "https://www.xxx.org.hk/tc/quantr/login",
    "status": 200,
    "timeout": 0,
    "upload": XMLHttpRequestEventTarget {},
    "withCredentials": true,
  },
  "status": 200,
  "statusText": undefined,
}

thanks
Peter

@ConnalATU
Copy link

does anyone have a fix for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants