Skip to content

Django 웹서버 통신 오류 #2

@wnsdudSoftkim

Description

@wnsdudSoftkim

웹서버와 통신시 Retrofit을 사용하여 HTTP 통신을 함.

package com.example.antiseptic

import android.media.Image
import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.*

object RetrofitClient {
    val retrofit = Retrofit.Builder()
        .baseUrl("https://b7c3be95402b.ngrok.io")
        .addConverterFactory(GsonConverterFactory.create())
        .build()
    val signupservice: SignUpService = retrofit.create(SignUpService::class.java)

}

//서버로 보내는 INPUT데이터
interface SignUpService {
    //베이스 URL 을 제외한 경로
    @FormUrlEncoded
    @POST("/app_signup")
    fun requestSignUp(
        @Field("email") email: String,
        @Field("password") password: String,
        @Field("name") name: String
        //@Field("Image") Image: ArrayList<taImage>
    ): Call<DataSignUp>

}
  1. 안드로이드 내부에서 http 로 통신을 하게 되면 오류가 나므로 https 로 보내야함
  2. .장고 웹서버를 ngrok 를 통해서 외부에서 접속할 수 있게끔 로컬 네트워크 터널을 열어줘야함.
  3. django 웹서버 에서 CSRF 쿠키 허용을 해줘야함 -> 데이터 통신 테스트를 위해 잠시 무효화
  4. retrofit은 json 타입으로 보내기에 django 측에서 json.parse 를 해줘야 하는 줄 알았는데 그냥
    request.POST.get 을 하면 데이터가 잘 넘어옴.

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is neededquestionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions