블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2735)
Unity3D (815)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-16 09:10

이번에는 HTTP 서버에 데이터 요청을 보내고 데이터를 얻어오기, 혹은 데이터를 보내는 방법입니다.


목차

1. WWW 클래스로 구현(권장하지 않습니다.)

2-1. Get 방식

2-2. Post 방식

2. UnityWebRequest 클래스로 구현(권장)

2-1. Get 방식

2-2. Post 방식

3. 요약 및 정리


1. WWW 클래스로 구현

1-1 GET 방식

아래는 제가 작성한 간단한 GET 방식의 코드입니다.

GET 방식 테스트를 위해 이곳을 이용하겠습니다.

https://developers.neople.co.kr/contents/apiDocs

 

Neople Developers

## 참고 사항 >- 타임라인 코드 다중 입력 시 콤마(,)를 이용해서 구분 처리   ex) /timeline?code=101,102,103 - startDate, endDate 요청 변수 사용 예시   ex) /timeline?startDate=20180901T0000&endDate=20180930T2359           /timeline?startDate=2018-09-01 00:00&endDate=2018-09-30 23:59   ※ 기간 검색

developers.neople.co.kr

 

APIKey는 로그인을 하시고 발급받으시면 보입니다.

응답 요청은 코루틴을 이용해서 보내도록 하겠습니다.

코루틴을 이용하는 이유는 응답을 보내고 오는 시간이 걸리기 때문입니다.

다른 곳에서 작성하시면 응답이 오기 전에 처리하게 되어 오류가 출력됩니다.

위에 코드는 예시 코드입니다.

홈페이지에서 발급받은 apikey를 저기에 입력하시면 됩니다.

url을 보시면 servers? apikey=하고 요청을 보내게 되는데

헤더 부분에 정보를 넣어서 보내는 곳이 저곳입니다.

코드에 주석을 넣었으니 읽으면서 확인해보세요.

코드를 실행해보시면 이렇게 응답이 옵니다.

1-2 POST 방식

위에는 POST 방식입니다.

POST 방식은 따로 동작을 처리해야 하기 때문에 개인적으로 만든 서버를 이용하여 설명하겠습니다.(저건 사설 ip 주소이기 때문에 똑같이 적으셔도 동작 안 합니다.)

(테스트해보고 싶으신 분들은 따로 서버를 만드셔서 실험해보세요)

POST 방식은? apikey= 이런 게 없습니다.

필드명에 apikey를 넣고 데이터를 넣으시면 됩니다.

필요한 내용은 주석 처리했습니다.

서버에서 로그인 정보가 맞으면 응답을 보냅니다.


2. unitywebrequest 클래스

이제 www 클래스는 Unity에서 사용을 권장하지 않습니다.

사용하시면 주의로 unitywebrequest를 사용하라고 나올 텐데요.

이것을 사용하는 방법을 알려드리겠습니다.

UnityEngine.Networking을 추가해줍니다.

2-1 GET 방식

아래는 WWW 클래스를 UnityWebRequest 클래스 방식으로 수정한 것입니다.

수정한 부분은 빨간 줄로 밑줄을 쳤습니다.

2-2 POST 방식

수정한 부분은 밑줄 쳤습니다.


3. 요약 및 정리

정리 : 통신방식에는 GET과 POST가 있다.

GET은 쉬우나 보안 취약, 용량 제한

POST는 어려우나 보안에 좋고, 용량 제한이 없다.

WWW 클래스는 이제 사용하지 않는다.

UnityWepRequest를 사용하자.(설명은 WWW 클래스에 적어놓았다.)

 

 

[출처] mungto.tistory.com/190

 

www 클래스, UnityWebRequest 클래스 사용하기(HTTP 서버에 데이터 가져오기, 보내기 등)

이번에는 HTTP 서버에 데이터 요청을 보내고 데이터를 얻어오기, 혹은 데이터를 보내는 방법입니다. 목차 1. WWW 클래스로 구현(권장하지 않습니다.) 2-1. Get 방식 2-2. Post 방식 2. UnityWebRequest 클래스

mungto.tistory.com

 

[참조] docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.Post.html

반응형
Posted by blueasa
, |


[링크] http://ucss.webjema.com/http/index.html

반응형
Posted by blueasa
, |

Android 나 PC 의 유니티에서 WWW 를 통해 파일을 받을 경우 IOS 는 해당 컨텐츠 헤더에 있는 값으로 자동으로 캐싱을 진행해 준다.

너무나 완벽한 OS 라서 문제가 생긴다..


아래 두가지 경우의 파일이 있다.



< Cache-Control 이 설정되어 있는 경우 >



< Cache-Control 이 없는 경우 >



Cache-Control 이 있는경우 IOS 에서는 해당 파일 캐싱을 진짜로 구현해 준다. ( 원래 이게 당연한 거지만.. )

따라서 저 만료 날자가 되기 전에 다시 같은 주소로 요청을 하면 새로 받아오지 않고 이전 캐싱된 데이터를 준다.


이 경우 가장 간단하게 해결하는 방법은 주소뒤에 의미없는 값을 추가하여 캐싱되지 않는 것처럼 꾸미는 것이다.

WWW( "http://www.naver.com/file.json?t=213948712" );

그러나 이 경우 클라이언트나 CDN 등에 쓸데없는 캐싱이 생길 수 있으며, 깔끔하지 않다.


가능한 Request 에서 요청 헤더에 다음과 같이 캐싱을 하지 않겠다고 추가하는것이 좋다.

WWWForm form = new WWWForm();

form.AddField( "Cache-Control", "no-cache" );




출처 : http://flystone.tistory.com/195

반응형
Posted by blueasa
, |

Load Textrue with WWW

Unity3D/Script / 2014. 12. 2. 00:59

[WWW.texture] : http://docs.unity3d.com/ScriptReference/WWW-texture.html

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
    IEnumerator Start() {
        WWW www = new WWW(url);
        yield return www;
        renderer.material.mainTexture = www.texture;
    }
}



[WWW.LoadImageIntoTexture] : http://docs.unity3d.com/ScriptReference/WWW.LoadImageIntoTexture.html

	// Continuously get the latest webcam shot from outside "Friday's" in Times Square
	// and DXT compress them at runtime
	var url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";

function Start () { // Create a texture in DXT1 format renderer.material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false); while(true) { // Start a download of the given URL var www = new WWW(url);

// wait until the download is done yield www;

// assign the downloaded image to the main texture of the object www.LoadImageIntoTexture(renderer.material.mainTexture); } }


반응형
Posted by blueasa
, |

WWW로 Texture를 다운받을 때, DDS, BMP,TGA는 다운이 안되길래 검색해보니..

WWW로는 PNG, JPG만 된다고 한다..

다른 포멧도 지원해주는 플러그인이 있길래 링크해놓는다.


Task #5: Loading DDS, BMP, TGA and other textures via WWW class in Unity3d

  
  This article describes the task: Load images via WWW class. Current version of Unity3d allows you to download images via WWW class only in PNG or JPG format (read more here:http://docs.unity3d.com/Documentation/ScriptReference/WWW-texture.html). But we should implement image loading in such formats as DDS, BMP, GIF, PSD, TGA etc. 


  Demo of application is shown on fig. 1.
Figure 1. – Demo of application
  
  All these image formats are supported by DevIL library (read more here:http://openil.sourceforge.net/features.php).
  There is no need for full application description, because DevIL library is well documented and has a lot of examples. I will show only the short description of implementation:
  • Load texture using WWW class;
  • Get bytes data using «bytes» field of WWW class;
  • Create DevIL texture from this data;
  • Get Color32[] array from DevIL texture;
  • Create Texture2D object based on this color array;

  To illustrate implementation I created a demo application. I want to notice that this application loads also MipMaps data from the texture, and creates proper Texture2D. 
  If you need more detailed description, or implement image loading not supported by unity3d, please write it in comments.


  Application demo you can download here:
  Source code you can download from here:



출처 : http://denis-potapenko.blogspot.kr/2013/04/task-5-loading-dds-bmp-tga-and-other.html

반응형

'Unity3D > Plugins' 카테고리의 다른 글

Unity3D WebView  (0) 2015.01.21
유니티 3D상에서 WebView 띄우기  (0) 2015.01.20
Log Viewer  (0) 2014.01.09
Mobile Movie Texture  (0) 2013.12.03
원격 로그 플러그인  (0) 2013.11.20
Posted by blueasa
, |