Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- css
- ๋ง์ผ๋ด๊ฐ์ธ์์๋ค์์ฐ๋ค๋ฉด
- database
- ์ฝ๋ฉ
- K๋ฐฐํฐ๋ฆฌ๋ ๋ณผ๋ฃจ์
- ์นํผ๋ธ๋ฆฌ์ฑ
- ์นํ์ด์ง๋ง๋ค๊ธฐ
- JavaScript
- ๋ ์
- ์ปดํจํฐ๊ณผํ
- ComputerScience
- Java
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- ๋ฐ์ํ
- html
- ์๋ฐ์คํฌ๋ฆฝํธ
- ๋ผํ๋ผ์ค์๋ง๋
- ๋ฆฌ์กํธ
- ๊ฐ๋ฐ
- ํ๋ก๊ทธ๋๋ฐ
- ์ฑ
- K๋ฐฐํฐ๋ฆฌ
- ํฐ์คํ ๋ฆฌ์ฑ๋ฆฐ์ง
- ์๋ฐ
- Python
- ์ค๋ผํด
- ํ์ด์ฌ
- ์ค๋ธ์
- ์ํ
- ๊น๋ฏธ๊ฒฝ์๋งํ์์
Archives
- Today
- Total
JiYoung Dev ๐ฅ
[Android] POST ๋ฐฉ์ ํต์ (2023.07.19~20) ๋ณธ๋ฌธ
ํ์๊ฐ์ , ๋ก๊ทธ์ธ ์ค์ต
github ์ฐธ์กฐ
node, android code
https://github.com/sin6338ki/Nodejs/tree/master/Ex13Android
https://github.com/sin6338ki/android/tree/main/AndServer
object :
๊ตฌํ์ฒด๋ฅผ 1ํ์ฑ์ผ๋ก ์ฌ์ฉํ๊ณ ์ถ์ ๋ ์ฌ์ฉ
//object: -> ๋ฌด๋ช
๊ฐ์ฒด๋ฅผ ์์ฑํ๋ ํค์๋
// StringRequest๋ฅผ ๊ตฌํํ๋ ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ฒ ๋ค!
// ์ผ๋ฐ์ ์ผ๋ก๋ ์ธํฐํ์ด์ค์์๋ ๊ฐ์ฒด ์์ฑ ๋ถ๊ฐ -> ๊ตฌํ์ ์ํ ํด๋์ค๋ฅผ ๋ง๋ค์ด์ ๊ฐ์ฒด๋ฅผ ์์ฑํจ
// ๊ทธ๋ฐ๋ฐ Bํ์
์ ๊ฐ์ฒด๋ฅผ ํ๋๋ง ์ฐ๊ณ ์ถ์ ๋ ํด๋์ค๋ฅผ ๋ง๋ค๊ธฐ์๋ ๋นํจ์จ์ ์
// ์ด๋ object ์ฌ์ฉ > ํ๋ฒ๋ง ์ธ ๊ฐ์ฒด๋ฅผ ๊ตฌํํ ๋ ์ฌ์ฉ!
val request = object:StringRequest(
Request.Method.POST,
"", //http ์์ฒญ
{
response ->
Log.d("response", response.toString())
},
{
error ->
Log.d("error", error.toString())
}
){
//post : ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ด ๋ณด๋ด๊ธฐ ์ํด ์์ฑํ๋ ๋ถ๋ถ
// ๋ฐํํ์
override fun getParams() : MutableMap<String, AndMemberVO>{
val params:MutableMap<String, AndMemberVO> = HashMap<String, AndMemberVO>()
//MutableMap์ interface๋ก ๊ฐ์ฒด ์์ฑ ๋ถ๊ฐ
val amv = AndMemberVO(inputId, inputPw, inputTel, inputBirth)
params.put("AndMember", amv) //ํ์์ ํ๋๋ก ๋ฌถ์ด์ ๋ณด๋ (memberVO)
return params
}
Mutable Map
gson ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉํ์ฌ json ํํ๋ก ๋ณํ ํ ์ ์ก
https://github.com/google/gson
override fun getParams() : MutableMap<String, String>{
//Map : ์ ์ , MutableMap : ์ ์ฐํ๊ฒ ์ฌ์ฉ๊ฐ๋ฅํ Map
val params:MutableMap<String, String> = HashMap<String, String>()
//MutableMap์ interface๋ก ๊ฐ์ฒด ์์ฑ ๋ถ๊ฐ
val amv = AndMemberVO(inputId, inputPw, inputTel, inputBirth)
//VO ์์ฒด๋ ํ ํ๋ซํผ์์ ์ฌ์ฉํ๊ธฐ์๋ ์ด๋ ค์ -> JSONํํ๋ก ๋ณํํ ๋ณด๋ด์ผ ํจ
//AndMemberVO(Object)-> JSON ํํ๋ก ๋ณํ
//GSON(goole์์ ๋ง๋ json์ ์ฝ๊ฒ ๋ค๋ฃฐ ์ ์๋๋ก ๋ง๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ) ์ฌ์ฉ
params.put("AndMember", Gson().toJson(amv)) //ํ์์ ํ๋๋ก ๋ฌถ์ด์ ๋ณด๋ (memberVO)
return params
}
Node์์ ๋ฐ์ ๋๋ ๋ฌธ์์ด๋ก ๋ฐ์์ง → JSON์ผ๋ก ๋ณํ
http ํต์ ์ ์ํ ๋ฐฉ๋ฒ
android:usesCleartextTraffic="true"
๋ฌธ์์ด๋ก ๋ค์ด์ด => jsonํํ๋ก ๋ฐ๊ธฐ
JSON.parse(req.body.AndMember)
'full stack > ์๋๋ก์ด๋' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Android] visibility & enabled ์์ฑ (2023.07.19) (0) | 2023.07.19 |
---|---|
[Android] JSON, GSON (2023.07.19) (0) | 2023.07.19 |
[Android] intent & listView ์ฌํ (2023.07.18) (0) | 2023.07.18 |
[Android] HTTP ํต์ - Volley (2023.07.18) (0) | 2023.07.18 |
[Android] listView ๋ง๋ค๊ธฐ (2023.07.14) (0) | 2023.07.14 |