最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

kotlin - why do i keep getting 400 bad request although my request is correct android - Stack Overflow

matteradmin6PV0评论

hello im using android app trying to parse the content from this api

BaseURL "/v1/"

URL
/stories

Parameters
page as int, optional
size as int, optional
location as 1 | 0, optional, default 0
Notes:
1 for get all stories with location
0 for all stories without considering location

Method
GET

Headers
Authorization: Bearer <token>

Response
{
    "error": false,
    "message": "Stories fetched successfully",
    "listStory": [
        {
            "id": "story-FvU4u0Vp2S3PMsFg",
            "name": "Dimas",
            "description": "Lorem Ipsum",
            "photoUrl": "/images/stories/photos-1641623658595_dummy-pic.png",
            "createdAt": "2022-01-08T06:34:18.598Z",
            "lat": -10.212,
            "lon": -16.002
        }
    ]
}

i already followed the api doc but i keep getting 400 bad req

this is my logcat

my api service

interface ApiService {
    @GET("stories")
    suspend fun getStories(
        @Header("Authorization") authorization: String,
        @Query("page") page: Int,
        @Query("size") size: Int,
    ): StoryResponse
}

my story repository

class StoryRepository(
    private val apiService: ApiService,
    private val sessionManager: SessionManager  
) {

    suspend fun getStories(token: String): List<ListStoryItem> {
        val token = sessionManager.getToken()  

        val page = 1
        val size = 10

        return apiService.getStories("Bearer $token", page, size).listStory
    }
}

i already test with thunder client and it return 200 this token is from prev test

Post a comment

comment list (0)

  1. No comments so far