locked
Can I GET the page content from external site in SPFx? RRS feed

  • Question

  • I want to get the page content from a external webpage but I receive the following CORS issue from console.

    Access to fetch at 'https://external-sites-url/index.php' from origin 'https://contoso.sharepoint.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

    Code:

        this.context.httpClient
          .get("https://external-sites-url/index.php"HttpClient.configurations.v1,
            {
              headers: {},
              mode"cors"
            })
          .then((resHttpClientResponse): Promise<any=> {
            console.log(res);
            return res.text()
          })
          .then((responseany): void => {
            console.log(response);
          });

    I am able to connect the external JSON API but not the html content. Is there a way to do it?

    Wednesday, September 16, 2020 3:52 AM

All replies