B4J Question [Solved] http request problem

behnam_tr

Active Member
Licensed User
Longtime User
hi

I get the following error when running this code
Which part of the code is wrong?
thanks ..

B4X:
Sub Getbalance(waddress As String) As ResumableSub
  
    'api help : https://docs.bscscan.com/v/bscscan-testnet/api-endpoints/accounts#get-bnb-balance-for-a-single-address

    Dim smsurl As String="https://api-testnet.bscscan.com/api"
    Dim token As String = "A3KV1EXZJFA13I4262YFKP1A3GX8MJMG9J"
  
    Dim objMap As Map
    objMap.Initialize
  
    objMap.Put("module" , "account")
    objMap.Put("action" , "balance")
    objMap.Put("address" , "0xcAdd45f32fDD44D7b65f97Cc056850067503BDC4")
    objMap.Put("apikey" ,token)
  
    Dim objJSon As JSONGenerator
    objJSon.Initialize(objMap)
  
    Dim j As HttpJob
    j.Initialize("j",Me)
    j.PostString(smsurl,objJSon.ToPrettyString(2))
    j.GetRequest.SetContentType("application/json")
    j.GetRequest.SetHeader("authorization",token )
  
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
      
        Log("Success...")
    Else
        Log("error...") 
      
    End If
    j.Release


End Sub


Log :
B4X:
Waiting for debugger to connect...
Program started.
ResponseError. Reason: , Response: <!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en-US"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en-US"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]-->
<head>
<title>Attention Required! | Cloudflare</title>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/cf.errors.css" />
<!--[if lt IE 9]><link rel="stylesheet" id='cf_styles-ie-css' href="/cdn-cgi/styles/cf.errors.ie.css" /><![endif]-->
<style>body{margin:0;padding:0}</style>
<!--[if gte IE 10]><!-->
<script>
  if (!navigator.cookieEnabled) {
    window.addEventListener('DOMContentLoaded', function () {
      var cookieEl = document.getElementById('cookie-alert');
      cookieEl.style.display = 'block';
    })
  }
</script>
<!--<![endif]-->
    <script>
    //<![CDATA[
    (function(){
      window._cf_chl_opt={
        cvId: "2",
        cType: "interactive",
        cNounce: "47332",
        cRay: "7318628a0e84b7e5",
        cHash: "d998194fdb79d15",
        cUPMDTk: "\/api?__cf_chl_tk=zbarhNt9WJLxjqs1rtI6YYEN8j18tgOMudnw2z7BGCA-1658956468-0-gaNycGzNByU",
        cFPWv: "b",
        cTTimeMs: "1000",
        cLt: "n",
        cRq: {
          ru: "aHR0cHM6Ly9hcGktdGVzdG5ldC5ic2NzY2FuLmNvbS9hcGk=",
          ra: "b2todHRwLzQuOS4w",
          rm: "UE9TVA==",
          d: "VmM8G2x+0/3lbQPdupEIVsm9KfoKourPKkvj6oQCvhx574MTKVycfT99EyRV4DWERV8C6l+iVxiSW8McpsXSkLhLE5sijogPOYyT5EHV/5IY2uZ+EPLKDgsuyivMc2DeOaWKiopc5XXVyCr5ExwIXxbLhRQKWROQm/Qk/S/nMUtgNpM0kykq+Ns1dyObw7uYOWgyfqA5sf8j65g0B9z79xZM6NdvpF++3K2l7QAfUdNJI8U6VVuZv9ToVGkLRmackl05RLHJSyNk1XyiDeIP258b/DVO0KZ5VR2ULrvYqhygYbTTI+EqMW56it6Y8sNvDf1EAv2w0uo1YF0mNtGLkbN8G416j28y1RTLmW4FhqyWCwT+N4ZNWPB4WgJX2xEgIeW2J5+sWq/JQADVssrX39S1oUFZ6xT36Yf28GareKPrAdIIuRzGWuR3B4J29ZQjq32KfLYlJYeDiY8wazqxXSc3Z1DxOGt5XLfJRBsPrtyQSA4rHcm5wKkRXt7Yqo0kUQeBOQ6rALYL2LLTNN19gTlYQKS3qwiz0T81oaL2YcPzyFgVwdVDJT6/HKiaaHMxwzZforFk60WOBsG6KDABR7WWsgm5P9g3uaY3YUYdOK0=",
          t: "MTY1ODk1NjQ2OC44MjAwMDA=",
          m: "Uj5On6+VGKC4u2wtqJzJxi9/bK3JsOSBQ0lJokDA1R8=",
          i1: "UqAmyxtKsq9YQuurCjP5mQ==",
          i2: "G2/jiG+dM+W8nbLCm8amYA==",
          zh: "Qdzt30w05SSNEnt2SHcgPWWgkLJnkQjTrp30vcMIKNM=",
          uh: "NTdK00yFFQQecirZvYitarrh0bgWEIleWaG8ZLeCKWg=",
          hh: "zQfhyPTQQqwvRob8nXdCWqWU7Fdz8JcuwmcV5F3Lh2c=",
        }
      };
    }());
    //]]>
    </script>
<style>
  #cf-wrapper #spinner {width:69px; margin:  auto;}
  #cf-wrapper #cf-please-wait{text-align:center}
  .attribution {margin-top: 32px;}
  .bubbles { background-color: #f58220; width:20px; height: 20px; margin:2px; border-radius:100%; display:inline-block; }
  #cf-wrapper #challenge-form { padding-top:25px; padding-bottom:25px; }
  #cf-hcaptcha-container { text-align:center;}
  #cf-hcaptcha-container iframe { display: inline-block;}
  @keyframes fader     { 0% {opacity: 0.2;} 50% {opacity: 1.0;} 100% {opacity: 0.2;} }
  #cf-wrapper #cf-bubbles { width:69px; }
  @-webkit-keyframes fader { 0% {opacity: 0.2;} 50% {opacity: 1.0;} 100% {opacity: 0.2;} }
  #cf-bubbles > .bubbles { animation: fader 1.6s infinite;}
  #cf-bubbles > .bubbles:nth-child(2) { animation-delay: .2s;}
  #cf-bubbles > .bubbles:nth-child(3) { animation-delay: .4s;}
</style>
</head>
<body>
  <div id="cf-wrapper">
    <div class="cf-alert cf-alert-error cf-cookie-error" id="cookie-alert" data-translate="enable_cookies">Please enable cookies.</div>
    <div id="cf-error-details" class="cf-error-details-wrapper">
      <div class="cf-wrapper cf-header cf-error-overview">
     
        <h1 data-translate="challenge_headline">One more step</h1>
        <h2 class="cf-subheadline"><span data-translate="complete_sec_check">Please complete the security check to access</span> api-testnet.bscscan.com</h2>
     
      </div>
     
      <div class="cf-section cf-highlight cf-captcha-container">
        <div class="cf-wrapper">
          <div class="cf-columns two">
            <div class="cf-column">
           
              <div class="cf-highlight-inverse cf-form-stacked">
                <form id="challenge-form" class="challenge-form interactive-form" action="/api?__cf_chl_f_tk=zbarhNt9WJLxjqs1rtI6YYEN8j18tgOMudnw2z7BGCA-1658956468-0-gaNycGzNByU" method="POST" enctype="application/x-www-form-urlencoded">
    <div id='cf-please-wait'>
      <div id='spinner'>
        <div id="cf-bubbles">
            <div class="bubbles"></div>
            <div class="bubbles"></div>
            <div class="bubbles"></div>
        </div>
      </div>
      <p data-translate="please_wait" id="cf-spinner-please-wait">Please stand by, while we are checking your browser...</p>
      <p data-translate="redirecting" id="cf-spinner-redirecting" style="display:none">Redirecting...</p>
      </div>
  <input type="hidden" name="md" value="qyMUWTnZq6xWUw9NFbotpCOBOBTcibPKcjpoHEf67LE-1658956468-0-ARe-PRQTKK4jaBkr4xzsawdI0Z2Yl_1Zm5ZUniNIgzroORyQ2wu4Y-tv_OrsJg5QTzuBDZRXQS3sJnTmP_H4yJD-YuhIks34OKNeX-cly3_kMc9DanriDzFLPtq4utZ9queHvtrvXUdo9jgJ1pzAvd-aNtz7qqPm19HRTKkDxgHNZshDiSYadYjYkm0axLWC1k2eOT2ThbEpN4cZWK67o91aBB3ZCPzIcO6SbKNr3cF5SOy7hZitjjMo2ZjsdjcfTDqkFHUyqXiFew-MBl2gprB2SUsT3Zlj2GBcVa689N7r7yWHlsYlAda1WsE9u-czK_rFVcs6aK2YWnTKrVoj45m1yMaZawEA4bHEWisviCP8973Ozv59D46Mt9MG9KHVwMAv8s3l_8pcuaocKN9Xzgb5fedKhlXlbPifMSPKbOcasMd02wRM3A3FDsu1Na0_Wi1QsT3x_SEWk9cYikUOfc2aNYnJKewYCOua_j0HL8dyqgV1t1Lra085xKpi6qALag3xryuFGr8JguJLDqeURW3EaN8wlsY-FvbHPpPCrlvKgMDO6XS7J1jwXXEZ0JnDUw2aMJXobvj_hqszcH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Kfjtv6RTZIvR/b3HWh1qF6wKT3w7RWYsq7HQdtQeFh9TcZdmXHUK7FCjunsWAESpI+nLILk56d7Ti8cpuJqOr/e6k9BhB8Mwy6qohg/5x4EEJK2ZpInBa3OZ2pvnEaUizOH7DFxVcLiqO4yhfq7t+GjPQ8T76VlPHFijOFMrQIOIUOvE3btD+bwInL+GTUL0b50eymXxEALaJZLGWUvU/cB3fKLi6ztuH/Y0R8tKRGLmNFHZWDE+aYSBDQ1XN17ssb8fJ0o/b8p5ycyIEapKGdHquEyEBCJh12r8UEdeIbwdyQvGh/ILTaNBgKQP+yKFdFBhrmJFaZWc0Y2iehVIxeyc2F5fedBmsmEjdPBrzN9AHVCiYMBBNXyJRmqpNzzvYgR2OSXmdkCmL4loXMw3TCt8BUzVwdMwN4IjNr36cNCP6UNLn8UM8F0L3YwgrYEybog+E6G54zdY4fX9C/gvmvzFMR0ghnzg+v8IOVFWsqDPh7jqbGxMWXbYPSC/ZXhIthFioPwmCOeeK77qtvIBBMir3TTSecZ5ANU9mDwTsO3VPiQCdGMClMQV8Nx2eg9g/6jBjCjQJDo0B2em/Wi7DpwMecsIin0eFzuhJuNraWkNAbCsD4kQ9kFv22Q8aSwh3OgDqpug7HiKBd7VHGuvV9+3DSNNJwmXy0IOWJogdfe56SiPyMEIk3FmqLT9caT5AMTcWz6cC6l5MW1E3/FHhNp8LHPeuOXoRVv1U3rTYm8SzW6SCuYrioQVtgYLLq2ZuZjr3Y5kD7TpqbkHb+s8Vkhb3hjJx+EDKwvxftmy3/5d63jq/i34fpfAzzz+MB97s7uYtBvSi+PSZbJrmyl+mqubMMkDqwRrjumRJLJS700i+">
  <input type="hidden" name="vc" value="b9ba5ea1951536679d445301ad26b73c">
  <noscript id="cf-captcha-bookmark" class="cf-captcha-info">
  <h1 data-translate="turn_on_js" style="color:#bd2426;">Please turn JavaScript on and reload the page.</h1>
  </noscript>
    <div id="no-cookie-warning" class="cookie-warning" data-translate="turn_on_cookies" style="display:none">
      <p data-translate="turn_on_cookies" style="color:#bd2426;">Please enable Cookies and reload the page.</p>
    </div>
  <script>
  //<![CDATA[
    var a = function() {try{return !!window.addEventListener} catch(e) {return !1} },
      b = function(b, c) {a() ? document.addEventListener("DOMContentLoaded", b, c) : document.attachEvent("onreadystatechange", b)};
      b(function(){
        var cookiesEnabled=(navigator.cookieEnabled)? true : false;
        if(!cookiesEnabled){
          var q = document.getElementById('no-cookie-warning');q.style.display = 'block';
        }
      });
  //]]>
  </script>
  <div id="trk_captcha_js" style="background-image:url('/cdn-cgi/images/trace/captcha/nojs/transparent.gif?ray=7318628a0e84b7e5')"></div>
</form>
  <script>
    //<![CDATA[
    (function(){
        var isIE = /(MSIE|Trident\/|Edge\/)/i.test(window.navigator.userAgent);
        var trkjs = isIE ? new Image() : document.createElement('img');
        trkjs.setAttribute("src", "/cdn-cgi/images/trace/captcha/js/transparent.gif?ray=7318628a0e84b7e5");
        trkjs.id = "trk_captcha_js";
        trkjs.setAttribute("alt", "");
        document.body.appendChild(trkjs);
        var cpo=document.createElement('script');
        cpo.type='text/javascript';
        cpo.src = '/cdn-cgi/challenge-platform/h/b/orchestrate/captcha/v1?ray=7318628a0e84b7e5';
       
        window._cf_chl_opt.cOgUHash = location.hash === '' && location.href.indexOf('#') !== -1 ? '#' : location.hash;
        window._cf_chl_opt.cOgUQuery = location.search === '' && location.href.slice(0, -window._cf_chl_opt.cOgUHash.length).indexOf('?') !== -1 ? '?' : location.search;
        if (window._cf_chl_opt.cUPMDTk && window.history && window.history.replaceState) {
          var ogU = location.pathname + window._cf_chl_opt.cOgUQuery + window._cf_chl_opt.cOgUHash;
          history.replaceState(null, null, "\/api?__cf_chl_rt_tk=zbarhNt9WJLxjqs1rtI6YYEN8j18tgOMudnw2z7BGCA-1658956468-0-gaNycGzNByU" + window._cf_chl_opt.cOgUHash);
          cpo.onload = function() {
            history.replaceState(null, null, ogU);
          };
        }
       
        document.getElementsByTagName('head')[0].appendChild(cpo);
    }());
    //]]>
    </script>
              </div>
            </div>
            <div class="cf-column">
              <div class="cf-screenshot-container">
             
                <span class="cf-no-screenshot"></span>
             
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="cf-section cf-wrapper">
        <div class="cf-columns two">
          <div class="cf-column">
            <h2 data-translate="why_captcha_headline">Why do I have to complete a CAPTCHA?</h2>
           
            <p data-translate="why_captcha_detail">Completing the CAPTCHA proves you are a human and gives you temporary access to the web property.</p>
          </div>
          <div class="cf-column">
            <h2 data-translate="resolve_captcha_headline">What can I do to prevent this in the future?</h2>
           
            <p data-translate="resolve_captcha_antivirus">If you are on a personal connection, like at home, you can run an anti-virus scan on your device to make sure it is not infected with malware.</p>
            <p data-translate="resolve_captcha_network">If you are at an office or shared network, you can ask the network administrator to run a scan across the network looking for misconfigured or infected devices.</p>
           
             
           
          </div>
        </div>
      </div>
     
      <div class="cf-error-footer cf-wrapper w-240 lg:w-full py-10 sm:py-4 sm:px-8 mx-auto text-center sm:text-left border-solid border-0 border-t border-gray-300">
  <p class="text-13">
    <span class="cf-footer-item sm:block sm:mb-1">Cloudflare Ray ID: <strong class="font-semibold">7318628a0e84b7e5</strong></span>
    <span class="cf-footer-separator sm:hidden">&bull;</span>
    <span id="cf-footer-item-ip" class="cf-footer-item hidden sm:block sm:mb-1">
      Your IP:
      <button type="button" id="cf-footer-ip-reveal" class="cf-footer-ip-reveal-btn">Click to reveal</button>
      <span class="hidden" id="cf-footer-ip">185.212.200.119</span>
      <span class="cf-footer-separator sm:hidden">&bull;</span>
    </span>
    <span class="cf-footer-item sm:block sm:mb-1"><span>Performance &amp; security by</span> <a rel="noopener noreferrer" href="https://www.cloudflare.com/5xx-error-landing" id="brand_link" target="_blank">Cloudflare</a></span>
   
  </p>
  <script>(function(){function d(){var b=a.getElementById("cf-footer-item-ip"),c=a.getElementById("cf-footer-ip-reveal");b&&"classList"in b&&(b.classList.remove("hidden"),c.addEventListener("click",function(){c.classList.add("hidden");a.getElementById("cf-footer-ip").classList.remove("hidden")}))}var a=document;document.addEventListener&&a.addEventListener("DOMContentLoaded",d)})();</script>
</div><!-- /.error-footer -->
    </div>
  </div>
  <script>
  window._cf_translation = {};
 
 
</script>
</body>
</html>
error...
 
Solution
I saw a lot of comments, I copied a piece of what I have ????
1659006976435.png


add:
j.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0")

B4X:
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
 
    Dim URL As String = "https://api-testnet.bscscan.com/api"
    Dim Parameters() As String = Array As String ("module" , "account", "action" , "balance", "address" , "0xcAdd45f32fDD44D7b65f97Cc056850067503BDC4", "apikey", "A3KV1EXZJFA13I4262YFKP1A3GX8MJMG9J" )
    Wait For (BscsSan(URL,Parameters)) Complete (DataResult As String)
    Log(DataResult)
 
End Sub

'You...

drgottjr

Expert
Licensed User
Longtime User
not sure why, but i'm given a reason:

ResponseError. Reason: Forbidden, Response: ...

your response didn't give one.

whenever you see Cloudfare, you have a problem. it's Captcha on
steroids. sites hand off an enhanced kind of i'm-not-a-robot test to Cloudare,
which gives thumbs up or down to your request. Cloudfare doesn't like you.
 

Attachments

  • cloudfare.png
    cloudfare.png
    17.7 KB · Views: 183
Upvote 0

behnam_tr

Active Member
Licensed User
Longtime User
not sure why, but i'm given a reason:

ResponseError. Reason: Forbidden, Response: ...

your response didn't give one.

whenever you see Cloudfare, you have a problem. it's Captcha on
steroids. sites hand off an enhanced kind of i'm-not-a-robot test to Cloudare,
which gives thumbs up or down to your request. Cloudfare doesn't like you.
same error
but its ok on chrome
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
I saw a lot of comments, I copied a piece of what I have ????
1659006976435.png


add:
j.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0")

B4X:
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
 
    Dim URL As String = "https://api-testnet.bscscan.com/api"
    Dim Parameters() As String = Array As String ("module" , "account", "action" , "balance", "address" , "0xcAdd45f32fDD44D7b65f97Cc056850067503BDC4", "apikey", "A3KV1EXZJFA13I4262YFKP1A3GX8MJMG9J" )
    Wait For (BscsSan(URL,Parameters)) Complete (DataResult As String)
    Log(DataResult)
 
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
End Sub

Public Sub BscsSan(URL As String, Parameters() As String) As ResumableSub
    Dim ResultURL As String
    Dim j As HttpJob
    Try
        j.Initialize("", Me)
        j.Download2(URL, Parameters)
        j.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0")
        j.GetRequest.SetHeader("Content-Type","application/json")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            ResultURL = j.GetString
        End If
    Catch
        Log(LastException.Message)
    End Try
    j.Release
    Return ResultURL
End Sub

1659007669067.png
 

Attachments

  • bscscan.zip
    3.2 KB · Views: 188
Last edited:
Upvote 1
Solution
Top