azureazure-functions

Unable to run Azure Function from portal


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/ig.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();
    }
}

Solution

  • 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:

    enter image description here

    enter image description here

    enter image description here

    Configure CORS to allow origins:

    enter image description here

    Portal:

    enter image description here