중요: UNet은 지원이 중단된 솔루션이며, 새로운 멀티플레이어 및 네트워킹 솔루션(게임 오브젝트용 넷코드)이 개발 중입니다. 자세한 내용과 다음 단계는 게임 오브젝트용 Unity 넷코드 웹사이트에 있는 정보를 참조하십시오. |
일부 최신 웹 애플리케이션은 HTTP PUT 동사를 통해 파일을 업로드하는 것을 선호합니다. 이 시나리오의 경우 Unity는 UnityWebRequest.PUT
함수를 제공합니다.
이 함수는 두 가지 인수를 사용합니다. 첫 번째 인수는 문자열이며, 요청에 타겟 URL을 지정합니다. 두 번째 인수는 문자열 또는 바이트 배열이며, 서버에 전송할 페이로드 데이터를 지정합니다.
함수 시그니쳐:
WebRequest.Put(string url, string data);
WebRequest.Put(string url, byte[] data);
UnityWebRequest
를 생성하고, 콘텐츠 타입을 application/octet-stream
으로 설정합니다.DownloadHandlerBuffer
를 UnityWebRequest
에 연결합니다. POST 함수와 마찬가지로, 이 함수를 사용하여 애플리케이션에서 결과 데이터를 반환할 수 있습니다.UploadHandlerRaw
오브젝트에 입력 업로드 데이터를 저장하고, UnityWebRequest
에 연결합니다. 그 결과 byte[]
함수를 사용하는 경우 UnityWebRequest.PUT
호출 이후 바이트 배열의 변경 사항은 서버에 업로드된 데이터에 반영되지 않습니다.using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class MyBehavior : MonoBehaviour {
void Start() {
StartCoroutine(Upload());
}
IEnumerator Upload() {
byte[] myData = System.Text.Encoding.UTF8.GetBytes("This is some test data");
UnityWebRequest www = UnityWebRequest.Put("https://www.my-server.com/upload", myData);
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success) {
Debug.Log(www.error);
}
else {
Debug.Log("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.