WKWebView lost body in NSURLProtocol

806 Views Asked by At

When I use NSURLProtocol to catch the requests from WKWebView, the body is lost. Any way to fix this issue?

1

There are 1 best solutions below

4
dgatwood On

NSURLRequest objects never have body data in protocols. You have to instead get the body stream, open it, and read the data in a streaming fashion.

For best performance, you should also resend that data to the write end of a new bound stream pair and provide the read end as the body stream in the new request. (Use the CFStreamCreateBoundPair function in the Core Foundation API and use a bridged cast it to cast the CFStreamRef object to an NSStream object.)