Home > Mobile >  WKWebview POST with Authorization Header return 500 Internal server error
WKWebview POST with Authorization Header return 500 Internal server error

Time:11-29

WKWebview Load request send 500 when the method set to Post. backend said that it is not even receiving the call. and it is sending a proper error when method is GET.

NSString *fullURL = _URL;

NSString *encodedStringUrl = [fullURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

NSURL *url = [NSURL URLWithString:encodedStringUrl];
NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];

NSString * token = [NSString stringWithFormat:@"bearer %@", [UserDefaults getAccessToken]];
NSDictionary * header = @{@"Content-Type": @"application/x-www-form-urlencoded",
                                         @"Authorization": token};

[requestObj setHTTPMethod:@"POST"];
[requestObj setAllHTTPHeaderFields:header];

[_webview loadRequest:requestObj];

is there any other way to load the request into WKWebView with Authorization header?

CodePudding user response:

If you ever encounter this error with WKWebView POST requests. Please check the server configurations for URL Module Redirect/ SSL redirect/ Cross Domain (CORS) issues. there is nothing to do from Mobile end. I had to make this post because Web and android was working fine and only the iOS was giving this error.

  • Related