API version 1

- ‐

createRequest

新しい非同期リクエストを作成します。

作成したリクエストは、FORMパラメータなどのプロパティ設定を行った後、 post または get メソッドによりサーバへ送信します。


HttpRequest オブジェクトは1回だけ通信を行うことができます。

複数の通信を行う場合、それぞれ createRequestメソッドにより別々のHttpRequestオブジェクトを作成してください。


HttpAsyncSessionオブジェクトとHttpRequestオブジェクトは密接に関連しています。

HttpRequestオブジェクトを作成したときのHttpAsyncSessionオブジェクト以外でGet、Postを行うことはできません。


FORMパラメータが不要な場合、createRequestメソッドは使用せず、getメソッドにURLを直接記述する形式を利用した方が効率的です。

呼出形式一覧

呼出形式

説明

CRS::Common::Net::HttpRequest createRequest(string id, string url)

新しい非同期リクエストを作成します。

戻り値一覧

戻り値

説明

CRS::Common::Net::HttpRequest

作成されたHttpRequestオブジェクト

引数一覧

引数

説明

id

セッションIDを指定します。

他の使用中のセッションIDと重複しないユニークな値を指定する必要があります。

すでに同じIDでリクエストが生成されている場合、例外が発生します。

url

要求するURLを指定します。

絶対パスまたは相対パス形式で指定可能です。

例外

識別子

説明

CRS::Common::Core-1:1

不正な値です

CRS::Common::Net::HttpAsyncSession-1:2

指定のIDはすでに使用されています

関連項目

getpost メソッド



使用例 CRSダウンロード

Form HTTPAsync2 {
   X = 0;
   Y = 0;
   width = 745;
   height = 441;
   reference ref;

   EditBox edtResult {
           x = 31;
           y = 127;
           Width = 369;
           Height = 123;
   }
   httpAsyncSession asyncSession {
           Function OnSessionEnd( e ) {
                   ^.edtResult += "ID=" + e.id + " / ステータスコード=" + Str(e.status) +
                           " / message=" + e.message + "\n/ body=" + e.response.body + "\n";
           }
   }

   Label Label3 {
           x = 31;
           y = 28;
           width = 351;
           height = 16;
           Value = "非同期通信機能(create後にpostを押します。1度のみ)";
   }

   TextBox txtURL1 {
           x = 32;
           y = 49;
           Width = 292;
           Height = 24;
           Value = "https://postman-echo.com/post";
   }

   Button Btn_CreateRequest {
           x = 31;
           y = 84;
           Width = 162;
           Height = 30;
           Title = "CreateRequest(ID, URL)";
           Function OnTouch( e ) {
                   try {
                           ^.ref.value = ^.asyncSession.createRequest("post", ^.txtURL1.Value);
                           ^.Btn_POST.Active = true;
                   }
                   catch(e) {
                           MessageBox("Message=" + str(e.Message) + "\nCategory=" + str(e.Category) + "\nCode="+ str(e.Code)  + "\nSubCode=" + str(e.subCode));
                   }
           }
   }

   Button Btn_POST {
           x = 230;
           y = 85;
           Width = 88;
           Height = 30;
           Title = "POST";
           Function OnTouch( e ) {
                   try{
                           var res = ^.asyncSession.post(^.ref.value);
                           /* Active = false; */
                   } catch(e){
                           MessageBox("Message=" + str(e.Message) + "\nCategory=" + str(e.Category) + "\nCode="+ str(e.Code)  + "\nSubCode=" + str(e.subCode));
                   }
           }
   }
}