skip to Main Content

I’m working on REST API with node.js and I used ‘request’ package. from the body of the function I get json data successfully on my window machine.

This is the code I have used:

await request.post(
    encodeURI(`https://hahu.io/api/send/otp`),
    {
      form: {
        secret: process.env.HAHU_API_KEY,
        mode: 'devices',
        type: 'sms',
        device: process.env.HAHU_DEVICE_KEY,
        sim: '1',
        phone: `+251${phone}`,
        message: 'Your OTP code is {{otp}}',
      },
    },
    (err, response, data) => {
      if (err) {
        console.log(err)
      }

      console.log(data)
      
    }
  )

And I got this result on my window machine.

{
  status: 200,
  message: 'OTP has been sent!',
  data: {
    phone: '+251900000009',
    message: 'Your OTP code is 552614',
    otp: 552614
  }
}

But on my linux ubuntu 22 server, it gives me html this

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="robots" content="noindex, nofollow">
    <title>One moment, please...</title>
    <style>
        body {
            background: #F6F7F8;
            color: #303131;
            font-family: sans-serif;
            margin-top: 45vh;
            text-align: center;
        }
    </style>
</head>
<body>
<h1>Please wait while your request is being verified...</h1>
<form id="wsidchk-form" style="display:none;" action="/z0f76a1d14fd21a8fb5fd0d03e0fdc3d3cedae52f" method="get">
    <input type="hidden" id="wsidchk" name="wsidchk"/>
</form>
<script>
    (function () {
        var west = +((+!+[] + !![]) + (+!+[] + !![] + !![] + !![] + !![] + !![] + []) + (+!+[] + !![] + !![] + !![]) + (+!+[] + !![] + !![] + !![] + !![] + !![] + []) + (+!+[] + !![] + !![] + !![] + !![] + !![]) + (+![] + []) + (+!+[] + !![] + !![] + !![] + !![] + !![] + !![] + !![])),
            east = +((+!+[] + !![]) + (+!+[] + !![] + !![] + []) + (+!+[]) + (+!+[] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + []) + (+!+[] + !![]) + (+![] + [])),
            x = function () {
                try {
                    return !!window.addEventListener;
                } catch (e) {
                    return !!0;
                }
            },
            y = function (y, z) {
                x() ? document.addEventListener("DOMContentLoaded", y, z) : document.attachEvent("onreadystatechange", y);
            };
        y(function () {
            document.getElementById('wsidchk').value = west + east;
            document.getElementById('wsidchk-form').submit();
        }, false);
    })();
</script>
</body>
</html>

What I want to do with the code is to make some logic based on the json result I get, but the code crash on server. I also tried with Axios and the result is the same.

What can be the issue and how can I solve it?

2

Answers


  1. This is caused due to a cloudflare’s security measure.
    Cloudflare is the middleman/broker between your machine and the "hahu.io" server.
    you can visit and see Here that cloudflare responds to BOTS how it has responded your request.

    Why not working on Ubuntu but Windows?

    • Probably your request headers need modification.
      May be something like

      headers = {
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15',
        'Accept': 'application/json',
        'Connection': 'keep-alive',
        'Accept-Encoding': 'gzip, deflate, br'
      }

      You can use CUSTOM HEADER with request like this.

    • If this does not solve the issue try proxy.
      GoodLuck!

    Login or Signup to reply.
  2. One possibility is an issue with the request package you’re using. You may want to try a different HTTP client library, such as axios or the built-in https module, to see if that resolves the problem.

    Another possibility is a problem with the server you’re sending requests to. The HTML response you’re seeing could result from a server error or maintenance page. You’ll need to reach out to the server administrator to resolve the issue if this is the case.

    There’s also possibly an issue with the network connection between your server and the one you’re sending requests to. This could be caused by a firewall or other network configuration problem.

    To troubleshoot the issue further, you might want to try the following:

    • Inspect the err object in the callback function to see if it provides clues about the problem.
    • Check the response object to see if it contains relevant information about the request and response.
    • Use curl to make the same request from the command line on your server. This can help you determine if the problem is with your code or the server you’re sending requests to.
    • Check the server logs for error messages that might provide more information about the issue.

    Reference that can be helpful: https://community.cloudflare.com/t/how-to-submit-our-crawler-as-cloudflare-verified-bot/354976

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search