uri | フォームデータが送信されるターゲット URI |
postData | Form body data. Will be URLEncoded prior to transmission. |
UnityWebRequest
UnityWebRequest は POST
を介して uri
にフォームデータを送信するように設定します。
Creates a UnityWebRequest configured to send form data to a server via HTTP POST
.
このメソッドは UnityWebRequest を作成し、url
をストリングの引数 uri
にセットし、method
を POST
にセットします。 Content-Type
ヘッダーはデフォルトでは application/x-www-form-urlencoded
にセットされます。
Note: サーバーバックエンド多くの言語は application/x-www-form-urlencoded
や multipart/form-data
よりも他のエンコーディングにセットする Content-Type
ヘッダーと一緒に POST
リクエストを正しく処理しません。
このメソッドは DownloadHandlerBuffer を UnityWebRequest にアタッチします。これは利便性のためにほとんどのユーザーが特に REST API のケースでサーバーからの応答を確認するために DownloadHandler を使うことを予想しています。
The data in postData
will be escaped, then interpreted into a byte stream via System.Text.Encoding.UTF8. The resulting byte stream will be stored in an UploadHandlerRaw and the Upload Handler will be attached to this UnityWebRequest.
using UnityEngine; using UnityEngine.Networking; using System.Collections;
public class MyBehavior : MonoBehaviour { void Start() { StartCoroutine(Upload()); }
IEnumerator Upload() { WWWForm form = new WWWForm(); form.AddField("myField", "myData");
using (UnityWebRequest www = UnityWebRequest.Post("https://www.my-server.com/myform", form)) { yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success) { Debug.Log(www.error); } else { Debug.Log("Form upload complete!"); } } } }
uri | フォームデータが送信されるターゲット URI |
formData | 書式設定とリモートサーバーへの送信のためフィールドをフォームします。またはファイルを WWWForm オブジェクトでカプセル化します。 |
UnityWebRequest
UnityWebRequest は POST
を介して uri
にフォームデータを送信するように設定します。
UnityWebRequest は HTTP POST
を介してサーバーにフォームデータを送信する設定を作成します。
このメソッドは UnityWebRequest を作成し、ストリングの引数 uri
に url
をセットし、method
を POST
にセットします。 Content-Type
ヘッダーは formData
パラメーターからコピーされます。
このメソッドは DownloadHandlerBuffer を UnityWebRequest にアタッチします。これは利便性のためにほとんどのユーザーが特に REST API のケースでサーバーからの応答を確認するために DownloadHandler を使うことを予想しています。FormData
オブジェクトはそのコンテンツに応じて適切にフォーマットされたバイトストリームを生成します。結果としてバイトストリームを UploadHandlerRaw に格納し、アップロードハンドラーはこの UnityWebRequest にアタッチします。
using UnityEngine; using UnityEngine.Networking; using System.Collections;
public class MyBehavior2 : MonoBehaviour { void Start() { StartCoroutine(Upload()); }
IEnumerator Upload() { WWWForm form = new WWWForm(); form.AddField("myField", "myData");
UnityWebRequest www = UnityWebRequest.Post("https://www.my-server.com/myform", form); yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success) { Debug.Log(www.error); } else { Debug.Log("Form upload complete!"); } } }
uri | フォームデータが送信されるターゲット URI |
multipartFormSections | フォームフィールドのリストまたはフォーマットされたリモートサーバーに送信するファイル |
boundary | マルチパートフォームのフォームフィールドを分離するとき使用されるユニークなバウンダリ(境界)文字列です。供給されていない場合、バウンダリは生成されます。 |
UnityWebRequest
UnityWebRequest は POST
を介して uri
にフォームデータを送信するように設定します。
UnityWebRequest は HTTP POST
を介してサーバーにフォームデータを送信する設定を作成します。
このメソッドは UnityWebRequest を作成し、url
をストリングの引数 uri
にセットし、method
を POST
にセットします。 Content-Type
ヘッダーは適切なバウンダリ仕様で multipart/form-data
にセットされます。
カスタム boundary
バイト配列を指定する場合はバイトシーケンスが一意であること保証する必要があり、フォームデータのボディのどこであろうとでてこない必要があることに注意してください。マルチパートフォームとフォームバウンダリーの詳細については RFC 2388 を参照してください。
このメソッドは DownloadHandlerBuffer を UnityWebRequest にアタッチします。これは利便性のためにほとんどのユーザーが特に REST API のケースでサーバーからの応答を確認するために DownloadHandler を使うことを予想しています。multipartFormSections
のIMultipartFormSection オブジェクトリストは有効なマルチパートフォームボディにフォーマットされます。各オブジェクトは個別のフォームセクションとしてインタプリタされます。このマルチパートフォームボディのフォーマット設定から生じるバイトストリームは UploadHandlerRaw で保存され、この UnityWebRequest にアタッチされます。
IMultipartFormSection の使用
フォームデータ指定をより細かく制御する方法を提供するために UnityWebRequest システムには (ユーザーが実装可能な) IMultipartFormSection インターフェイスが含まれています。標準的なアプリケーションのために Unity にデフォルトでデータとファイルセクションの実装が用意されています。
参照: MultipartFormDataSection 、[[MultipartFormFileSection]
IMultipartFormSection リストオブジェクトはこのメソッドを提供できます。リストのメンバーは RFC 2388 で定義されているマルチパート形式にフォーマットされます。
マルチパートフォームはフィールド間の分離を定義する任意のバウンダリーストリングが必要となります。バウンダリーストリングはリクエストにおいてどのフォームフィールドのボディ内のどこにも存在しないと保証しなければなりません。バウンダリーを指定しない場合、Unity は バウンダリーを生成します。生成されたバウンダリーは 40 のランダムな Printable バイトです。フォームフィールドデータと正確な一致は必要とされていません。ただし、アプリケーションがカスタムのバウンダリーストリングを指定する必要がある場合、行うことがあります。
指定したバウンダリーがあれば、バイト配列から UTF-8 文字列に自動的に変換されます。
using UnityEngine; using UnityEngine.Networking; using System.Collections;
public class MyBehavior3 : MonoBehaviour { void Start() { StartCoroutine(Upload()); }
IEnumerator Upload() { WWWForm form = new WWWForm(); form.AddField("myField", "myData");
UnityWebRequest www = UnityWebRequest.Post("https://www.my-server.com/myform", form); yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success) { Debug.Log(www.error); } else { Debug.Log("Form upload complete!"); } } }
uri | フォームデータが送信されるターゲット URI |
formFields | フォームフィールドのキーと値を示すストリング。自動的に URL エンコードされたフォームボディにフォーマットされます。 |
UnityWebRequest
UnityWebRequest は POST
を介して uri
にフォームデータを送信するように設定します。
UnityWebRequest は HTTP POST
を介してサーバーにフォームデータを送信する設定を作成します。
このメソッドは UnityWebRequest を作成し、ストリングの引数 uri
に url
をセットして /method/を POST
にセットします。 Content-Type
ヘッダーは application/x-www-form-urlencoded
にセットされます。
The Dictionary of strings in formFields
will be interpreted as a list of form fields whose field IDs are the dictionary keys, and whose field values are the dictionary values. Both keys and values will be escaped, and then joined into a URL-encoded form string. (for example, key1=value1&key2=value2
).
このメソッドはデフォルトでは DownloadHandlerBuffer を UnityWebRequest にアタッチします。これは利便性のために、特に REST API のケースでほとんどのユーザーがサーバーからの応答を確認する DownloadHandler を使用すると予想してます。FormFields
から生成される URL エンコードされたフォームストリングをバイトストリームに変換して UploadHandlerRaw に格納します。これは UnityWebRequest にアタッチされます。
using UnityEngine; using UnityEngine.Networking; using System.Collections;
public class MyBehavior4 : MonoBehaviour { void Start() { StartCoroutine(Upload()); }
IEnumerator Upload() { WWWForm form = new WWWForm(); form.AddField("myField", "myData");
UnityWebRequest www = UnityWebRequest.Post("https://www.my-server.com/myform", form); yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success) { Debug.Log(www.error); } else { Debug.Log("Form upload complete!"); } } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.