Access to fetch at 'http://127.0.0.1:9998/tika' from origin 'http://127.0.0.1:8081' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
text.html:30
PUT http://127.0.0.1:9998/tika net::ERR_FAILED
尽管网页和服务都运行在同一台机器上(即使用相同的IP地址 127.0.0.1),但它们通过不同的端口(8081 和 9998)进行通信,这仍然被视为跨源(CORS,Cross-Origin Resource Sharing)请求。在 Web 安全中,CORS 策略用于限制哪些外部网站可以访问你的资源。即使两个资源都在同一台机器上,只要端口不同,它们就被视为不同的源。
当使用 Postman 或类似的 API 测试工具(如 cURL)能够成功访问 http://127.0.0.1:9998/tika 而浏览器却因为 CORS 策略阻止访问时,原因主要在于 CORS 策略是浏览器安全功能的一部分,它限制了从脚本(如通过 <script>标签、AJAX调用 等)发起的跨源 HTTP 请求。
Postman 和 cURL 等工具不是浏览器,它们不受浏览器安全策略(如 CORS)的限制。这些工具直接向服务器发送 HTTP 请求,并接收服务器的响应,而不会检查或应用 CORS 策略。
解决方法:下载浏览器插件(如 CORS Unblock)来临时禁用 CORS 检查。但请注意,这种方法仅适用于开发环境,并且不应在生产环境中使用。
<properties><parsers><parserclass="org.apache.tika.parser.ocr.TesseractOCRParser"><params><!-- these are the defaults; you only need to specify the ones you want
to modify --><paramname="applyRotation"type="bool">false</param><paramname="colorSpace"type="string">gray</param><paramname="density"type="int">300</param><paramname="depth"type="int">4</param><paramname="enableImagePreprocessing"type="bool">false</param><paramname="filter"type="string">triangle</param><paramname="imageMagickPath"type="string">D:\ImageMagick</param><paramname="language"type="string">eng</param><paramname="maxFileSizeToOcr"type="long">2147483647</param><paramname="minFileSizeToOcr"type="long">0</param><paramname="pageSegMode"type="string">1</param><paramname="pageSeparator"type="string"></param><paramname="preserveInterwordSpacing"type="bool">false</param><paramname="resize"type="int">200</param><paramname="skipOcr"type="bool">false</param><paramname="tessdataPath"type="string">D:\Tesseract-OCR\tessdata</param><paramname="tesseractPath"type="string">D:\Tesseract-OCR</param><paramname="timeoutSeconds"type="int">120</param></params></parser></parsers></properties>