Access to this address through nodejs or php is blocked by Alibaba Cloud,How can I access the correct return value of this link in nodejs or php?

Viewed 67

Access to this address through nodejs or php is intercepted by Alibaba Cloud, but json data can be returned by visiting this address directly in the browser, How can I access the correct return value of this link in nodejs or php?

https://mall.xsyxsc.com/user/product/indexWindows

Direct access on the browser will return the following data:

{"rspCode":"illegalArgumentError","rspDesc":"indexWindows.areaId: 区域id不能为空, indexWindows.openBrandHouse: 是否开通品牌馆不能为空, indexWindows.storeId: 门店id不能为空","data":null}

Use nodejs https or php curl, the following prompt will be returned:

很抱歉,由于您访问的URL有可能对网站造成安全威胁,您的访问被阻断。 您的请求ID是: 2f6a1f9316055959054642583e43d3

Below is an example of my request with php:

<?php
    function getRequest($url){
        $headerArray = [
            'Host'=>'mall.xsyxsc.com',
            'User-Agent'=>'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0',
            'Accept'=>'*/*',
            'Accept-Language'=>'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
            'Accept-Encoding'=>'gzip, deflate',
            'Cache-Control'=>'max-age=0'    
        ];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch,CURLOPT_HTTPHEADER,$headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        //将返回的json对象解码成数组对象并返回
        //$output = json_decode($output,true);
        return $output;
    }

    $res = getRequest('https://mall.xsyxsc.com/user/product/indexWindows');
    // $res = getRequest('https://www.baidu.com/');
    exit($res);
1 Answers

ShaoGong

It looks like a firewall rule. When you are using curl, it's a different request. Your Alibaba Cloud Firewall is blocking that access so you get a 405 error.

You can open your Web Application Firewall logs right after your curl request, so you can spot the problem and configure some firewall rule allowing that request type or that source IP address.

Find here more information on how to check your firewall logs: https://www.alibabacloud.com/help/doc-detail/100503.htm?spm=a2c63.l28256.b99.90.20a82f0dHJsHV1

Find here how to configure the policy: https://www.alibabacloud.com/help/doc-detail/42780.htm?spm=a2c63.p38356.879954.7.49fa1f5eoVOECk#concept-gy3-jbp-p2b

Related