Home>

I opened a local php server and node js. The browser is an appeal to node js, and since it has more to do post a request for php. As long as I work locally, post a request to node js on php goes well, everything works. Now I threw php files on hosting, and already turning at hosting get error 403. Tell me how to make a request to the local node js server to a remote php.

The code nodejs express:

const instance= axios.create ({
  baseURL: api.SERVER_URI,
  withCredentials: true
});
app.post ( '/init /', (request, response)= >
 {
  let result;
  if (config.licKey.length=== 16) {
    const userIdSync= machineIdSync ({original: true});
    const pathCheat= path.resolve ( "./") replace (/\\ /g, "/").;
    instance.post ( `/user /initialize /`, {
      licKey: config.licKey,
      pathCheat: pathCheat,
      userIdSync: userIdSync
    }). Then (function (res) {
      if (res.data.resultCode=== 1) {
        store.set ( 'user', res.data.user);
        let user= store.get ( 'user');
        if (user.user_gamePath.length >
 0) {
          result= {success: 1, message: user.user_gamePath};
        } ELSE {
          result= {success: 0, message: 'Do not specify the path to the game'};
        }
        response.json (result);
      } ELSE {
        result= {success: 0, message: res.data.message};
      }
    }). Catch (function (err) {
      console.log (err);
      result= {success: 0, message: 'Error accessing the server'};
      response.json (result);
    });
  } ELSE {
    result= {success: 0, message: 'Invalid data'};
    response.json (result);
  }
});

Error:

Error: Request failed with status code 403
    at createError (D: \ GitHub \ wallHack \ node_modules \ axios \ lib \ core \ createError.js: 16: 15)
    at settle (D: \ GitHub \ wallHack \ node_modules \ axios \ lib \ core \ settle.js: 17: 12)
    at IncomingMessage.handleStreamEnd (D: \ GitHub \ wallHack \ node_modules \ axios \ lib \ adapters \ http.js: 269: 11)
    at IncomingMessage.emit (events.js: 388: 22)
    at endReadableNT (internal /streams /readable.js: 1336: 12)
    at processTicksAndRejections (internal /process /task_queues.js: 82: 21) {
  config: {
    url: '/user /initialize /',
    method: 'post',
    data: '',
    headers: {
      Accept: 'application /json, text /plain, * /*',
      'Content-Type': 'application /json',
      'User-Agent': 'axios /0.21.4',
      'Content-Length': 114
    }
    baseURL: 'http://testdeveloper.ru',
    transformRequest: [[Function: transformRequest]],
    transformResponse: [[Function: transformResponse]],
    timeout: 0
    withCredentials: true,
    adapter: [Function: httpAdapter],
    XSRFCOOKIENAME: 'XSRF-TOKEN',
    xsrfheadername: 'x-xsrf-token',
    MaxContentLength: -1,
    MaxBodyLength: -1,
    ValidateStatus: [Function: ValidateStatus],
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    }
  }
  Request: <
Ref * 1 >
 ClientRequest {
    _events: [Object: null prototype] {
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      socket: [Function (anonymous)],
      timeout: [Function (anonymous)],
      prefinish: [Function: requestOnPrefinish]
    }
    _EventScount: 7,
    _Maxlisteners: undefined,
    OutputData: [],
    Outputsize: 0,
    Writable: True,
    Destroyed: False,
    _Last: True,
    Chunkedencoding: False,
    Shouldkeepalive: False,
    _DefaultKeepalive: True
    USCHUNKEDENCODINGBYDEFAULT: TRUE,
    SendDate: False,
    _RemovedConnection: false,
    _RemovedContlen: False,
    _Removedte: False,
    _ContentLength: NULL,
    _Hasbody: True,
    _Trailer: '',
    FINISHED: TRUE,
    _Headersent: TRUE,
    socket: Socket {
      connecting: false,_hadError: false, _parent: null,
      _host: 'testdeveloper.ru',
      _readableState: [ReadableState],
      _Events: [Object: NULL PROTOTYPE],
      _EventScount: 7,
      _Maxlisteners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: null,
      _server: null,
      Parser: NULL,
      _httpMessage: [Circular * 1]
      [Symbol (async_id_symbol)]: 13,
      [Symbol (kHandle)]: [TCP],
      [Symbol (kSetNoDelay)]: false,
      [Symbol (lastWriteQueueSize)]: 0,
      [Symbol (timeout)]: null,
      [Symbol (kBuffer)]: null,
      [Symbol (kBufferCb)]: null,
      [Symbol (kBufferGen)]: null,
      [SYMBOL (KCAPTURE)]: False,
      [Symbol (kBytesRead)]: 0,
      [Symbol (kBytesWritten)]: 0,
      [Symbol (RequestTimeout)]: undefined
    }
    _Header: 'POST /User /Initialize /http /1.1 \ r \ n' +
      'Accept /Application /JSON, Text /Plain, * /* \ r \ n' +
      'Content-Type: Application /JSON \ R \ N' +
      'User-Agent: Axios /0.21.4 \ R \ n' +
      'Content-Length: 114 \ R \ n' +
      'Host: TestDeveloper.ru \ R \ n' +
      'Connection: Close \ R \ n' +
      '\ r \ n',
    _keepaliveTimeout: 0,
    _ONpendingData: [Function: NooppendingOutput],
    agent: Agent {
      _Events: [Object: NULL PROTOTYPE],
      _eventsCount: 2
      _Maxlisteners: undefined,
      defaultPort: 80,
      Protocol: 'http:',
      options: [Object],
      requests: {},
      sockets: [Object],
      freeSockets: {},
      keepAliveMsecs: 1000
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 1,
      [Symbol (kCapture)]: false
    }
    Socketpath: undefined,
    Method: 'Post',
    Maxheadersize: undefined,
    INSECUREHTTPPARSER: undefined,
    Path: '/user /initialize /',
    _ENDED: TRUE,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _Events: [Object: NULL PROTOTYPE],
      _eventsCount: 3
      _Maxlisteners: undefined,
      Socket: [Socket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      headers: [Object],
      rawHeaders: [Array],
      trailers: {},
      rawTrailers: [],
      ABORDED: FALSE,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 403
      statusMessage: 'Forbidden',
      client: [Socket],
      _consuming: false,
      _dumped: false,
      req: [Circular * 1]
      responseUrl: 'http://testdeveloper.ru/user/initialize/',
      redirects: [],
      [SYMBOL (KCAPTURE)]: False,
      [Symbol (RequestTimeout)]: undefined
    }
    ABORDED: FALSE,
    TimeOutcb: NULL,
    UpgradeorConnect: False,
    Parser: NULL,
    MaxHeadersCount: NULL,
    ReusedSocket: False,
    Host: 'TestDeveloper.ru',
    Protocol: 'http:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _Events: [Object: NULL PROTOTYPE],
      _eventsCount: 2
      _Maxlisteners: undefined,
      _options: [Object],
      _ENDED: TRUE,
      _ending: true,
      _redirectCount: 0
      _redirects: [],
      _requestBodyLength: 114
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular * 1]
      _currentUrl: 'http://testdeveloper.ru/user/initialize/',
      [Symbol (kCapture)]: false
    }
    [SYMBOL (KCAPTURE)]: False,
    [Symbol (Kneeddrain)]: False,
    [Symbol (Corked)]: 0,
    [Symbol (kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'Content-type': [Array],
      'User-agent': [Array],
      'Content-length': [Array],
      host: [Array]
    }
  }
  response: {
    status: 403
    statusText: 'Forbidden',
    headers: {
      server: 'nginx-reuseport /1.21.1',
      date: 'Tue, 14 Sep 2021 15:18:19 GMT',
      'Content-type': 'text /html',
      'Content-length': '163'
      connection: 'close'
    }
    config: {
      url: '/user /initialize /',
      method: 'post',
      data: '',
      headers: [Object],
      baseURL: 'http://testdeveloper.ru',
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0Withcredentials: True, Adapter: [Function: httpadapter],
      XSRFCOOKIENAME: 'XSRF-TOKEN',
      xsrfheadername: 'x-xsrf-token',
      MaxContentLength: -1,
      MaxBodyLength: -1,
      ValidateStatus: [Function: ValidateStatus],
      Transitional: [Object]
    }
    Request: <
Ref * 1 >
 ClientRequest {
      _Events: [Object: NULL PROTOTYPE],
      _EventScount: 7,
      _Maxlisteners: undefined,
      OutputData: [],
      Outputsize: 0,
      Writable: True,
      Destroyed: False,
      _Last: True,
      Chunkedencoding: False,
      Shouldkeepalive: False,
      _DefaultKeepalive: True
      USCHUNKEDENCODINGBYDEFAULT: TRUE,
      SendDate: False,
      _RemovedConnection: false,
      _RemovedContlen: False,
      _Removedte: False,
      _ContentLength: NULL,
      _Hasbody: True,
      _Trailer: '',
      FINISHED: TRUE,
      _Headersent: TRUE,
      Socket: [Socket],
      _Header: 'POST /User /Initialize /http /1.1 \ r \ n' +
        'Accept /Application /JSON, Text /Plain, * /* \ r \ n' +
        'Content-Type: Application /JSON \ R \ N' +
        'User-Agent: Axios /0.21.4 \ R \ n' +
        'Content-Length: 114 \ R \ n' +
        'Host: TestDeveloper.ru \ R \ n' +
        'Connection: Close \ R \ n' +
        '\ r \ n',
      _keepaliveTimeout: 0,
      _ONpendingData: [Function: NooppendingOutput],
      Agent: [Agent],
      Socketpath: undefined,
      Method: 'Post',
      Maxheadersize: undefined,
      INSECUREHTTPPARSER: undefined,
      Path: '/user /initialize /',
      _ENDED: TRUE,
      Res: [incomingmessage],
      ABORDED: FALSE,
      TimeOutcb: NULL,
      UpgradeorConnect: False,
      Parser: NULL,
      MaxHeadersCount: NULL,
      ReusedSocket: False,
      Host: 'TestDeveloper.ru',
      Protocol: 'http:',
      _Redirectable: [Writable],
      [SYMBOL (KCAPTURE)]: False,
      [Symbol (Kneeddrain)]: False,
      [Symbol (Corked)]: 0,
      [Symbol (Koutheaders)]: [Object: NULL PROTOTYPE]
    }
    Data: '<
HTML >
\ r \ n '+
      '≪
HEAD >
≪
Title >
403 Forbidden <
/title >
≪
/Head >
\ r \ n '+
      '≪
Body >
\ r \ n '+
      '≪
CENTER >
≪
H1 >
403 Forbidden <
/h1 >
≪
/CENTER >
\ r \ n '+
      '≪
HR >
≪
CENTER >
NGINX-REUSEPORT /1.21.1 <
/CENTER >
\ r \ n '+
      '≪
/Body >
\ r \ n '+
      '≪
/HTML >
\ r \ n '
  }
  Isaxioserror: True,
  TOJSON: [FUNCTION: TOJSON]
}

Look what the error does 403 mean and think well

ArchDemon2021-09-17 01:33:12

I have been sitting all day with this problem, I understand that this is a restriction of access, but even when I just fit the link to the address line, then I get a result, and if I just make an appeal to PHP, then everything works, an error only When I do this from under Node JS

Amely Flovs2021-09-17 01:33:12

Display the API.Server_URI value into the log, view your request error closer carefully

nörbörnën2021-09-17 01:33:12

Added a mistake in question. API.Server_uri stores just host server, and changes to dev or prod

Amely Flovs2021-09-17 01:33:12

OK. With a simple pitch, I found out that your "external service" returns 403 to those whom he considers a "robot". So give him a "User-Agent" header, which will arrange it, for example, "Mozilla /5.0 (Platform; RV: geckuestion) GECKO /GECKOTRAIL FIREFOX /Firefoxversion"

nörbörnën2021-09-17 01:33:12