JSON Response from Django in Android

后端 未结 2 920
一个人的身影
一个人的身影 2021-01-06 03:38

I am trying to get a jSON response in Android from my Django based web backend. The response I am getting is

03-19 16:32:32.120: I/System.out(7442): This si          


        
相关标签:
2条回答
  • 2021-01-06 03:54

    TL;DR
    httpconn.setRequestProperty("Accept", "application/json");


    HttpURLConnection's default "Accept" HttpHeader value is text/html, image/gif, image/jpeg, *; q=.2, /; q=.2

    When text/html is used django returns JSON wrapped with HTML. In case when plain JSON is needed, Accept HttpHeader value should be set to 'application/json'

    0 讨论(0)
  • 2021-01-06 04:08

    The response was redirecting me to the custom login-page where I had used @csrf_exempt. Further login details were required for code to process the info. I added the login parameter along with my call and the desired response was obtained

    0 讨论(0)
提交回复
热议问题