Usage of External Resource Client with Microsoft GraphApi not working

Hello all,

I was trying to convert a plugin that uses the graphapi through curl call to be compatible with cloud v13.

Therefor I converted all curl call with recommended ExternalApiCalls but post calls are not working.

I converted the following code

    $curl = curl_init();

    $default_options = array(
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => false,
    );
    curl_setopt_array($curl, $default_options);

    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
    if (count($curl_header) > 0) {
        curl_setopt($curl, CURLOPT_HTTPHEADER, $curl_header);
    }

    if (is_array($curl_query_params) && count($curl_query_params) > 0) {
        $url .= '?' . http_build_query($curl_query_params);
    }

    if ($method == "GET") {
        if (is_array($params) && count($params) > 0) {
            $url .= '?' . http_build_query($params);
        }
    } elseif ($method == "POST") {
        curl_setopt($curl, CURLOPT_POST, true);
        if (is_string($params)) {
            curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
        } else {
            curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));
        }
    } elseif ($method == "PUT") {
        curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
    } elseif ($method == "DELETE") {
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));
    }

    curl_setopt($curl, CURLOPT_URL, $url);

    $curl_response = curl_exec($curl);

    curl_close($curl);

    $json_decoded = json_decode($curl_response, true);
    return $json_decoded;

to the following code

    $erc = new ExternalResourceClient(60, 10);

    $body = null;
    if ($method == "GET") {
        if (is_array($params) && count($params) > 0) {
            $url .= '?' . http_build_query($params);
        }
    } else {
        if (is_string($params)) {
            $body = $params;
        } else {
            $body = json_encode($params);
        }
    }

    $response = $erc->request($method, $url, $body, $headers);
    $rContent = $response->getBody()->getContents();

    $json_decoded = json_decode($rContent, true);
    return $json_decoded;

 Then I try some calls, all "GET" calls are working and returning the expected data, but "POST" calls are returning the content of the "https://developer.microsoft.com/en-us/graph" web page.

I first thought that it might be linked to the IP resolution that is returning "ags.privatelink.msidentity.com." instead of an IP V4, but after modifying core to remove the IP resolution, I still have the same result.

So it seems linked to the file_get_contents behavior.

Did you have any similar experiences, do you have any idea for a workaround ?