POST Asynchronous Request
サーバーに対して非同期リクエストを行う
説明
POST メソッドを使用してサーバーに対して非同期リクエストを行います。非同期実行において、通常、この手順がプロセスの最初に行われます。
以下のセクションでは、JSON をデータ シリアル化形式として使用します。Java® クライアント API で protobuf をデータ シリアル化形式として使用する方法を説明する例については、Asynchronous RESTful Requests Using Protocol Buffers in the Java ClientおよびAsynchronous RESTful Requests Using Protocol Buffers in .NET Clientを参照してください。
リクエスト
HTTP メソッド
POST
URI
http://host:port/deployedArchiveName/matlabFunctionName
クエリ パラメーター
| 名前 | 説明 | 値のタイプ |
|---|---|---|
mode | (必須)。通信のモードを指定します。 |
|
client | (オプション)。リクエストを行うクライアントの ID または名前を指定します。 |
|
例:
?mode=async&client=Nor101
コンテンツ タイプ
application/json
本文
| 名前 | 説明 | 値のタイプ |
|---|---|---|
nargout | クライアント アプリケーションが、デプロイされた MATLAB® 関数からリクエストしている出力の数。意図された目的に応じて、複数の出力を返すように MATLAB 関数をコーディングできます。 | number |
rhs | デプロイされた MATLAB 関数の入力引数。コンマ区切り値の配列として指定します。 | [arg1,arg2,arg3,...] |
outputFormat | レスポンス内の MATLAB 出力を詳細の JSON 表現または簡易の JSON 表現のいずれを使用して返す必要があるのか、および MATLAB データ型の JSON 表現の詳細については、MATLAB データ型の JSON 表現を参照してください。 | { "mode" : "small | large", "nanInfFormat" : "string | object" } |
例:
単一の入力引数:
{
"nargout": 1,
"rhs": [5],
"outputFormat": { "mode" : "small", "nanInfFormat" : "object" }
}{
"nargout": 2,
"rhs": [3, 4, 5 ...],
"outputFormat": { "mode" : "large", "nanInfFormat" : "string" }
}レスポンス
成功
201 Created
| 名前 | 説明 | 値のタイプ |
|---|---|---|
id | 特定のリクエストの ID。 | {id-string} |
self | 特定のリクエストの URI。 リクエストの状態やリクエストの結果を取得するなど、その他の非同期実行リクエストで URI を使用します。 | {request-uri-string} |
up | サーバー上のリクエストのコレクションを表示するために使用する URI。詳細については、GET Collection of Requestsを参照してください。 | {request-collection-uri-string} |
lastModifiedSeq | self で表されるリクエストがいつ最終変更されたのかを示す数値。 | {server-state-number} |
state | リクエストの状態。 |
状態の一覧: READING IN_QUEUE PROCESSING READY ERROR CANCELLED |
client | リクエストの開始時にクエリ パラメーターとして指定したクライアント ID または名前。 | {client-id-string} |
例:
{
"id": "a061c723-4724-42a0-b405-329cb8c373d6",
"self": "/~e4a954fd-5eaf-4b54-aac2-20681b33d075/requests/a061c723-4724-42a0-b405-329cb8c373d6",
"up": "/~e4a954fd-5eaf-4b54-aac2-20681b33d075/requests",
"lastModifiedSeq": 6,
"state": "READING",
"client": ""
} |
エラー
404 ResourceNotFound
405 MethodNotAllowed — 'Access-Control-Allow-Origin' ヘッダーはありません。サーバー上で CORS を有効にします。
415 InvalidContentType
415 UnsupportedMediaType
サンプル呼び出し
HTTP
リクエスト: POST /mymagic/mymagic?mode=async HTTP/1.1
Host: localhost:9910
Content-Type: application/json
{"rhs":[7],"nargout":1,"outputFormat":{"mode":"small","nanType":"string"}}レスポンス: Status Code: 201 Created
Header:
Location: /~e4a954fd-5eaf-4b54-aac2-20681b33d075/requests/ad2363f3-26c1-4d48-88f8-6b7fb615f254
X-MPS-Start-Time: 003472d705bd1cd2
Content-Length: 248
Body:
{
"id": "ad2363f3-26c1-4d48-88f8-6b7fb615f254",
"self": "/~e4a954fd-5eaf-4b54-aac2-20681b33d075/requests/ad2363f3-26c1-4d48-88f8-6b7fb615f254",
"up": "/~e4a954fd-5eaf-4b54-aac2-20681b33d075/requests",
"lastModifiedSeq": 41,
"state": "READING",
"client": ""
} |
JavaScript
var data = JSON.stringify(
{ "rhs": [7],
"nargout": 1,
"outputFormat": {"mode": "small","nanType": "string"}
}
);
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:9910/mymagic/mymagic?mode=async");
xhr.setRequestHeader("content-type", "application/json");
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.send(data); |
バージョン履歴
R2016b で導入