Я сделал миграцию UIWebView на WKWebView. Я успешно выполнил миграцию. Но в моем приложении есть один функционал. Функциональность заключается в том, что пользователь получает данные загруженного URL и отправляет их на наш сервер при нажатии кнопки. Эта функция отлично работает с UIWebView, но не работает с WKWebView. Код:
NSURL *fileURL = [self.webView URL];
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:fileURL completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error)
{
}] resume];
Возвращаемое значение приведенного выше кода при использовании UIWebView:
данные:
<OS_dispatch_data: data[0x10bb8c000] = { composite, size = 1184733, num_records = 1037 record[0] = { from = 0, length = 769, data_object = 0x174c66c40 }, record[1] = { from = 0, length = 2352, data_object = 0x17506cb80 }, record[2] = { from = 0, length = 711, data_object = 0x17467fb00 }, record[3] = { from = 0, length = 3361, data_object = 0x17427b400 }, record[4] = { from = 0, length = 4072, data_object = 0x174e79b80 }, record[5] = { from = 0, length = 4072, data_object = 0x174e7ec80 }, record[6] = { from = 0, length = 4072, data_object = 0x174c7ca40 }, record[7] = { from = 0, length = 771, data_object = 0x174e60ac0 }, record[8] = { from = 0, length = 1024, data_object = 0x17506bfc0 }, record[9] = { from = 0, length = 2277, data_object = 0x174c61c80 }, record[10] = { from = 0, length = 786, data_object = 0x17127dac0 }, record[11] = { from = 0, length = 309, data_object = 0x174a71400 }, record[12] = { from = 0, length = 1730, data_object = 0x174c72c00 }, record[13] = { from = 0, length = 1247, data_object = 0x17506bf40 }, record[14] = { from = 0, length = 792, data_object = 0x174a7d180 }, record[15] = { from = 0, length = 2048, data_object = 0x171261780 }, record[16] = { from = 0, length = 1024, data_object = 0x171278fc0 }, record[17] = { from = 0, length = 208, data_object = 0x170275800 }, record[18] = { from = 0, length = 807, data_object = 0x17106a6c0 }, record[19] = { from = 0, length = 1024, data_object = 0x175067c80 }, record[20] = { from = 0, length = 2241, data_object = 0x174e68840 }, record[21] = { from = 0, length = 4072, data_object = 0x174271680 }, record[22] = { from = 0, length = 1047, data_object = 0x171466300 }, record[23] = { from = 0, length = 90, data_object = 0x170e7ad40 }, record[24] = { from = 0, length = 2935, data_object = 0x174e76bc0 }, record[25] = { from = 0, length = 1143, data_object = 0x170e7e8c0 }, record[26] = { from = 0, length = 2048, data_object = 0x170a7ce80 }, record[27] = { from = 0, length = 881, data_object = 0x17506ad80 }, record[28] = { from = 0, length = 2182, data_object = 0x175067640 },>
ответ:
<NSHTTPURLResponse: 0x174e2f1e0> { URL: https://student.globalpay.wu.com/geo-buyer/services/buyer/downloadInstruction } { status code: 200, headers {
"Cache-Control" = "no-cache, no-store, must-revalidate";
"Content-Disposition" = "file; filename = instructions.pdf";
"Content-Type" = "application/pdf";
Date = "Fri, 31 Jul 2020 14:12:45 GMT";
Expires = "Thu, 01 Jan 1970 00:00:00 GMT";
Pragma = "no-cache";
Server = none;
"Strict-Transport-Security" = "max-age=31536000";
"x-edgeconnect-midmile-rtt" = 207;
"x-edgeconnect-origin-mex-latency" = 706;
"x-powered-by" = "Servlet/3.0 JSP/2.2";
} }
ошибка:
nil
Возвращаемое значение указанного выше кода при использовании WKWebView:
данные:
<OS_dispatch_data: data[0x170e637c0] = { leaf, size = 113, buf = 0x1702f8480 }>
ответ:
<NSHTTPURLResponse: 0x170a3de00> { URL: https://student.globalpay.wu.com/geo-buyer/services/buyer/downloadInstruction } { status code: 500, headers {
"Cache-Control" = "no-cache, no-store, must-revalidate";
"Content-Length" = 113;
"Content-Type" = "application/xml";
Date = "Fri, 31 Jul 2020 10:03:55 GMT";
Expires = "Thu, 01 Jan 1970 00:00:00 GMT";
Pragma = "no-cache";
Server = none;
"Set-Cookie" = "JSESSIONID=ba2kU_-n1BeO_GDhBgzEds4kHpr8oDzGSFVEmYln5DAtTMYQVhCS!2050459021; path=/; secure; HttpOnly";
"Strict-Transport-Security" = "max-age=31536000";
"gpfs.invalid.session" = true;
"x-edgeconnect-midmile-rtt" = 210;
"x-edgeconnect-origin-mex-latency" = 51;
"x-powered-by" = "Servlet/3.0 JSP/2.2";
} }
ошибка:
nil
Точка - это код состояния обоих значений ответа, в UIWebView код состояния ответа - 200, а код состояния ответа WKWebView - 500. Также значение данных отличается .
Я не знаю, почему получают другое значение.
Я хочу получить такие же данные и ответ, как UIWebView.