0

I have do migration of UIWebView to WKWebView. I have successfully done migration. But in my app there is one functionality. The functionality is user fetch data of loaded URL and send to our server when click on button. This functionality work fine with UIWebView, but not work with WKWebView. Code:

NSURL *fileURL = [self.webView URL];
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:fileURL completionHandler:^(NSData *data,
                                                          NSURLResponse *response,
                                                          NSError *error)
{

}] resume];

Return value of above code when use UIWebView:

data:

<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 },>

response:

<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";
} }

error:

nil

Return value of above code when use WKWebView:

data:

<OS_dispatch_data: data[0x170e637c0] = { leaf, size = 113, buf = 0x1702f8480 }>

response:

<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";
} }

error:

nil

Point is status code of both response value is different, in UIWebView response status code is 200 and WKWebView response status code is 500. Also data value is different.

I don't know why getting different value.

I want to fetch same data and response like UIWebView.

Yogendra Patel
  • 813
  • 2
  • 8
  • 24
  • I doubt it's an issue with `UIWebView` or `WKWebView` since you're only using them to get the `url` – Sylvan D Ash Aug 01 '20 at 08:38
  • Can you add the code of how you're fetching the data in Swift? – Sylvan D Ash Aug 01 '20 at 08:39
  • @SylvanDAsh issue with WKWebVew may be it's cookie related issue. – Yogendra Patel Aug 01 '20 at 08:51
  • But you're getting the correct url when you use `WKWebView`, and from your code it seems like you use `URLSession` to load the url...hence why it doesn't seem to be a `WKWebView` issue, unless there are other parameters you're including? – Sylvan D Ash Aug 01 '20 at 08:55
  • @SylvanDAsh Yeah, you say correct. I also having doubt about this, but before 1 houri get point related cookie. WKWebView not save cookie like UIWebView, so may be this is a problem for current issue. Still i am not sure. – Yogendra Patel Aug 01 '20 at 09:01
  • What if you just try to load the url directly without using `UIWebView` or `WKWebView`? – Sylvan D Ash Aug 01 '20 at 09:03
  • @SylvanDAsh In UIWebView, it's return same response as current, also in WKWebView, same response as current. Issue is related cookie, please check this link https://stackoverflow.com/a/24982211/6617215 – Yogendra Patel Aug 01 '20 at 09:40
  • I see. Maybe you could also include, in the question, that your request needs to use cookies stored in the webview? – Sylvan D Ash Aug 01 '20 at 09:45
  • `Also data value is different.`: Did you try to print the data, as String? There might be a more explicit error message there? – Larme Aug 03 '20 at 07:59

0 Answers0