API:Cross-site requests/ja

ユーザー スクリプトやガジェットで別の MediaWiki サイトに対してAPI 呼出しを行う必要がある場合 (たとえば、英語版ウィキペディアのスクリプトが Commons の画像情報を確認する必要がある場合)、JSONP または CORSを使う必要があります.



JSONP の使用
The API's  accepts a   parameter, whose value is a JavaScript function which the JSON result will be wrapped in. This may be used to call the API on a remote site by dynamically adding tags to the document.

例


GET リクエスト


レスポンス


CORS の使用
The MediaWiki API requires that the  be supplied as a query string parameter, with the value being the site from which the request originates, which is matched against the Origin header required by the CORS protocol. Note that this parameter must be included in any pre-flight request, and so should be included in the query string portion of the request URI even for POST requests.

When the  parameter is supplied and the request does not return a successful CORS response, MediaWiki≥1.30  will return a   header with a brief reason for the failure, e.g. in case of mismatched origin or unsupported headers in a   request header.

Unauthenticated CORS Requests
Unauthenticated CORS requests may be made from any origin by setting the  request parameter to. In this case MediaWiki will include the  header in the response and will process the request as if logged out.

例


GET リクエスト


Authenticated CORS Requests
To make an authenticated CORS request, the remote wiki's  setting must be set to allow the origin site. If the CORS origin check passes, MediaWiki will include the  header in the response, so authentication cookies may be sent.

では、JavaScript で CORS を呼び出す、より多くの手順と例を記しています.



追加的な注記
JSONPとCORSの詳細な違いは、CORS vs JSONPで参照可能です.

