skip to Main Content

When I run the Azure Function from the portal, I get this error:

{"message": "Failed to fetch",
"stack": "TypeError: Failed to fetch
at https://portal.azure.com/Content/Dynamic/BeUd4hejqUig.js:113:24094",
"isError":true}

Please help me resolve it.

My code is:

package JWS;

import java.util.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;

/**
 * Azure Functions with HTTP Trigger.
 */
public class JWSwithRSA {
    /**
     * This function listens at endpoint "/api/JWSwithRSA". Two ways to invoke it using "curl" command in bash:
     * 1. curl -d "HTTP Body" {your host}/api/JWSwithRSA
     * 2. curl {your host}/api/JWSwithRSA?name=HTTP%20Query
     */
    @FunctionName("JWSwithRSA")
    public HttpResponseMessage run(
            @HttpTrigger(name = "req", 
            methods = {HttpMethod.GET, HttpMethod.POST}, 
            authLevel = AuthorizationLevel.FUNCTION) 
            HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {
        context.getLogger().info("Java HTTP trigger processed a request.");
        return request.createResponseBuilder(HttpStatus.OK).body("Welcome ").build();
    }
}

2

Answers


  1. Running your function in portal requires the app to explicitly accept requests from https://portal.azure.com. This is known as cross-origin resource sharing (CORS). Configure CORS to add https://portal.azure.com to allowed origins.

    enter image description here

    The other reasons you might not be able to run the function app is due to network restrictions.

    Login or Signup to reply.
  2. As mentioned in comments, this error occurs if the Network access restrictions is enabled in Azure function App=>Networking=>Inbound traffic configuration.

    enter image description here

    To resolve this:

    • Enable access to all networks.

    enter image description here

    • Or whitelist the Ip Address or grant virtual network access.

    enter image description here

    enter image description here

    Configure CORS to allow origins:

    enter image description here

    Portal:

    • After enabling network access, able to run the function successfully.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search