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
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.
The other reasons you might not be able to run the function app is due to network restrictions.
As mentioned in comments, this error occurs if the Network access restrictions is enabled in
Azure function App=>Networking=>Inbound traffic configuration
.To resolve this:
Configure CORS to allow origins:
Portal: