(1) ASP.NET <-> MySQL ( https://blog.naver.com/titetoto123/221340254753 )
(2) Unity <-> ASP.NET ( https://blog.naver.com/titetoto123/221343429335 )
★ Unity -> ASP.NET 요청 ★
> 더 보기 |
public void Test() { StartCoroutine(RequestTest()); } IEnumerator RequestTest() { WWWForm form = new WWWForm(); form.AddField("id", "20"); UnityWebRequest www = UnityWebRequest.Post("http://localhost:59751/api/UseridsByWWWForm", form); yield return www.SendWebRequest(); if(www.isNetworkError || www.isHttpError) { Debug.LogError( "http://localhost:59751/api/UseridsByWWWForm : " + www.error ); } else { Debug.LogError( "http://localhost:59751/api/UseridsByWWWForm : " + www.downloadHandler.text ); } } |
★ ASP.NET. Unity 요청 받는 부분 ★
> 더 보기 |
[Route("api/UseridsByWWWForm")] [HttpPost] public IHttpActionResult GetProductByWWWForm() { HttpContextWrapper httpContext = (HttpContextWrapper)Request.Properties["MS_HttpContext"]; string foo = httpContext.Request.Form["id"]; Int64 i64PersonID = Int64.Parse(foo); var product = userInfos.FirstOrDefault((p) => p.m_i64PersonID == i64PersonID); if (product == null) { return NotFound(); } |
★ ASP.NET -> MySQL DB 프로시저 호출 ★
> 더 보기 |
[Route("api/UseridsByWWWForm")] [HttpPost] public IHttpActionResult GetProductByWWWForm() { HttpContextWrapper httpContext = (HttpContextWrapper)Request.Properties["MS_HttpContext"]; string foo = httpContext.Request.Form["id"]; Int64 i64PersonID = Int64.Parse(foo); var product = userInfos.FirstOrDefault((p) => p.m_i64PersonID == i64PersonID); if (product == null) { return NotFound(); } // DB 테스트 OdbcConnection connect; try { using(connect = new OdbcConnection( ConfigurationManager.ConnectionStrings["MySQLConnStr"].ConnectionString )) { connect.Open(); OdbcCommand cmd = new OdbcCommand("{CALL P_User_Info_Add(?,?,?)}", connect); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("ParamUserID", foo); cmd.Parameters.AddWithValue("ParamPassword", foo); cmd.Parameters.AddWithValue("ParamUUID", foo); cmd.ExecuteNonQuery(); if(connect.State == System.Data.ConnectionState.Open) { connect.Close(); } } } catch(Exception ex) { return Ok("DB Error"); } return Ok(product); } |
★ 프로시저 및 결과 ★
'프로그래밍 - 서버 > ASP.NET' 카테고리의 다른 글
★ 16. ASP.NET MySQL 연결 ★ (0) | 2018.09.14 |
---|---|
★ 15. Session 세션 상태 ★ (0) | 2018.09.14 |
★ 14. 웹 서버. 쿠키(Cookie) 저장 사용 ★ (0) | 2018.09.14 |
★ 13. 페이지들 사이의 정보 전달 ★ (0) | 2018.09.14 |
★ 12. 뷰 상태 (현재 페이지 내용 저장) ★ (0) | 2018.09.14 |