RunApi

RunApi


本地/局域网

<p>如果你是使用runapi客户端 ( <a href="https://www.showdoc.cc/runapi" title="https://www.showdoc.runapi"><a href="https://www.showdoc.cc/runapi">https://www.showdoc.cc/runapi</a></a> ),则会自动跨域,可以请求本地和局域网的接口,不需要用户额外操作。但如果你是使用在线精简版( <a href="http://runapi.showdoc.cc" title="http://runapi.showdoc.cc"><a href="http://runapi.showdoc.cc">http://runapi.showdoc.cc</a></a> )则需要在API的服务器上设置允许跨域。在服务器返回API结果的时候,也顺便返回三个允许跨域的http header,其结构如下:</p> <pre><code>Access-Control-Allow-Origin: * Access-Control-Allow-Credentials : true Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie</code></pre> <p>至于服务器如何操作http header ,各语言有各语言的实现。php的实现如下所示:</p> <pre><code>// 允许 runapi.showdoc.cc 发起的跨域请求 header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Credentials : true"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie");</code></pre> <p>其他的语言的实现也同理。你可以上网搜索下如何更改http header的代码,此处不再一一列举。注意,项目上生产环境前,请把以上代码注释掉,以免暴露安全隐患。</p>

页面列表

ITEM_HTML