简体   繁体   中英

laravel curl not working on azure

I am connecting my two apps (laravel with python) using curl command. It is working absolutely fine on my local server without changing a single line but when it gives me following error when on azure server

POST https://myweb.com/searchJobs 500 ()

my code is

$ch = curl_init();

    //URL to send the request to

    curl_setopt($ch, CURLOPT_URL, 'http://python-scrapper-python001.azurewebsites.net/myfunction');

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));

    //We are doing a post request
    curl_setopt($ch, CURLOPT_POST, 1);

    //adding the post data to request
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);

    //Return instead of outputting directly
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $output = curl_exec($ch);
        curl_close($ch);

is there any security protocol that I need to update on azure or what can be possible issue?

Actually these lines were working fine on localhost but not on azure

$arr = "";
$arr['hello'] = '7';

so I changed them as

$arr = [];
$arr['hello'] = '7';

Though i don't no why azure didn't run it. If php convert it to an array on localhost than it must run on azure as well

Since you are using the default domain provided by azure appservice. Instead of just using the HTTP protocol try to use the HTTPS since this is already free on the default domain provided. in this case try this changes.

$ch = curl_init();

    //URL to send the request to

    curl_setopt($ch, CURLOPT_URL, 'https://python-scrapper-python001.azurewebsites.net/myfunction');

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));

    //We are doing a post request
    curl_setopt($ch, CURLOPT_POST, 1);

    //adding the post data to request
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);

    //Return instead of outputting directly
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $output = curl_exec($ch);
        curl_close($ch);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM