Ios 在调用UIWebView的loadHTMLString时拦截和修改资源/url请求

Ios 在调用UIWebView的loadHTMLString时拦截和修改资源/url请求,ios,objective-c,swift,uiwebview,webimage,Ios,Objective C,Swift,Uiwebview,Webimage,我正在使用loadHTMLString方法在UIWebView上加载一些HTML字符串 HTML字符串如下所示 <html> <head></head> <body> <!-- [DocumentBodyStart:9ab3216e-b945-4432-141f-68164c25f0d6] --> <div class="jive-rendered-content">

我正在使用loadHTMLString方法在UIWebView上加载一些HTML字符串

HTML字符串如下所示

<html>
    <head></head>
    <body>
        <!-- [DocumentBodyStart:9ab3216e-b945-4432-141f-68164c25f0d6] -->
        <div class="jive-rendered-content"> 
            <p class="">Test description</p> 
            <a href="https://a-team-906-test.jivelandia.com/servlet/JiveServlet/previewBody/1091-102-1-1054/IMG_0005.JPG">
                <img src="https://a-team-906-test.jivelandia.com/servlet/JiveServlet/previewBody/1091-102-1-1054/IMG_0005.JPG">
            </a>
        </div>
        <!-- [DocumentBodyEnd:9ab3216e-b945-4432-141f-68164c25f0d6] -->
        <script type="text/javascript" src="web/video-loading-events.js" onerror="alert('cant load video-loading-events.js')"></script>
    </body><br>
</html>
正如您所见,HTML内容中有一个图像URL。问题是由于身份验证问题,图像无法加载到WebView上

那么,我如何拦截图像url请求以查看引擎盖下发生了什么?如果需要的话,我怎样才能在特定的请求中添加额外的头呢


Objective-C更可取,但Swift也受欢迎。提前感谢。

一个好的开始是使用safari web inspector查看当您在应用程序中打开webview时,哪些错误被注销到控制台

您需要从iPhone中启用web inspector,然后确保在safari中启用了菜单栏中的“显示开发”菜单

完成这两项操作后,您可以在safari中导航到Develop->->

从开发者窗口刷新页面,查看注销的内容

祝你好运

<html>
    <head></head>
    <body>
        <!-- [DocumentBodyStart:9ab3216e-b945-4432-141f-68164c25f0d6] -->
        <div class="jive-rendered-content"> 
            <p class="">Test description</p> 
            <a href="https://a-team-906-test.jivelandia.com/servlet/JiveServlet/previewBody/1091-102-1-1054/IMG_0005.JPG">
                <img src="https://a-team-906-test.jivelandia.com/servlet/JiveServlet/previewBody/1091-102-1-1054/IMG_0005.JPG">
            </a>
        </div>
        <!-- [DocumentBodyEnd:9ab3216e-b945-4432-141f-68164c25f0d6] -->
        <script type="text/javascript" src="web/video-loading-events.js" onerror="alert('cant load video-loading-events.js')"></script>
    </body><br>
</html>