简体   繁体   中英

WKWebview POST with Authorization Header return 500 Internal server error

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM