Sending identical HTTP POST request succeeds from reqbin.com but fails from kotlin mobile app

I am trying to build a simple ping function to a mobile app. I want to send a ping from the app to an azure web app which should receive the ping and save it to an SQL database. I am developing the app in java and kotlin.
So far I have identified that the json payload I send from the app is not formatted correctly, or at least cannot be formatted correctly when received in the web app. I get a ‘Json input formatter’ exception from Azure Log Streams when I send a ping from the app.

I have tried to verify if my api was faulty be testing with reqbin.com, but sending the exact same json payload I do not get an error, and I cannot figure out why it works from reqbin but not from the app when the json is identical.

Any help would be greatly appreciated.

The class i use for constructing the json payload to send is in kotlin, like this:

*am importing all the stuff

fun createJsonPing(
    timeOfPing: LocalDateTime,
    deviceId: String,
    smartphoneId: String,
    note: String
): String {
    
    val messageObject = JSONObject()
    try {
        // convert the datetime to correct format
        val isoDateTimeString = timeOfPing.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)

        messageObject.put("TimeOfPing", formatDateTimeToISO(timeOfPing))
        messageObject.put("SmartphoneId", smartphoneId)
        messageObject.put("DeviceId", deviceId)
        messageObject.put("Note", note)
    } catch (e: Exception) {
        e.printStackTrace()
        throw JSONException(e.message ?: "Unknown error")
        Log.i("createJsonPing", "Failed to construct Json ping")
    }

    val jsonMessageStringPing = messageObject.toString()

    Log.i("createPing", "Ping: n" + jsonMessageStringPing)

    Log.i("createPing", "Size of ping is: ${jsonMessageStringPing.toByteArray(Charsets.UTF_8).size} b")
   return jsonMessageStringPing
}

fun formatDateTimeToISO(dateTime: LocalDateTime): String {
    val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")
    return dateTime.format(formatter)
}

I then send the json using Ktor like this:

// set up client
    private val client = HttpClient(CIO) {
        install(Logging) {
            level = LogLevel.ALL
        }
        install(ContentNegotiation) {
            json(Json {
                ignoreUnknownKeys = true
                prettyPrint = true
                //isLenient = true
            })
        }
    }

suspend fun simpleSend() {

        try  {
            val response: HttpResponse = client.post("https://myazurewebapp.azurewebsites.net/ping") {
                headers {
                    append(HttpHeaders.Accept, "application/json")
                    append(HttpHeaders.ContentType, "application/json")
                }
                //contentType(ContentType.Application.Json) // <--have also trying using this
                setBody(createJsonPing(
                    LocalDateTime.now(),
                    "TEST",
                    "test",
                    "testing ping"))
            }.body()

            Log.i(TAG, "HTTP Response: $response")
        } catch (e: Exception) {
            Log.i(TAG, "Request failed: $e")
        } finally {
            close()
        }
    }

The format of the json i send looks like this:

{"TimeOfPing":"2024-06-21T14:38:00.121",
"SmartphoneId":"TEST",
"DeviceId":"test",
"Note":"testing ping"}

And i get an error from Azure Log Streams in my web app like this:

2024-06-21 12:20:50.894 +00:00 [Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request starting HTTP/1.1 POST https://myazurewepapp.azurewebsites.net/ping - application/json 127
2024-06-21 12:20:50.894 +00:00 [Trace] Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware: All hosts are allowed.
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Routing.Matching.DfaMatcher: 1 candidate(s) found for the request path '/ping'
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Endpoint 'api.Controllers.MessagePingController.Create (api)' with route pattern 'api/ping' is valid for the request path '/ping'
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware: Request matched endpoint 'api.Controllers.MessagePingController.Create (api)'
2024-06-21 12:20:50.894 +00:00 [Trace] Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware: The endpoint does not specify the IRequestSizeLimitMetadata.
2024-06-21 12:20:50.894 +00:00 [Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executing endpoint 'api.Controllers.MessagePingController.Create (api)'
2024-06-21 12:20:50.894 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Route matched with {action = "Create", controller = "MessagePing"}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Create(api.Dtos.MessagePing.CreateMessagePingRequestDto) on controller api.Controllers.MessagePingController (api).
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Execution plan of authorization filters (in the following order): None
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Execution plan of resource filters (in the following order): None
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Execution plan of action filters (in the following order): Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter (Order: -3000), Microsoft.AspNetCore.Mvc.Infrastructure.ModelStateInvalidFilter (Order: -2000)
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Execution plan of exception filters (in the following order): None
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Execution plan of result filters (in the following order): Microsoft.AspNetCore.Mvc.Infrastructure.ClientErrorResultFilter (Order: -2000)
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Executing controller factory for controller api.Controllers.MessagePingController (api)
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Executed controller factory for controller api.Controllers.MessagePingController (api)
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder: Attempting to bind parameter 'MessagePingDto' of type 'api.Dtos.MessagePing.CreateMessagePingRequestDto' ...
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder: Attempting to bind parameter 'MessagePingDto' of type 'api.Dtos.MessagePing.CreateMessagePingRequestDto' using the name '' in request data ...
2024-06-21 12:20:50.894 +00:00 [Debug] Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder: Selected input formatter 'Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonInputFormatter' for content type 'application/json'.
----
2024-06-21 12:20:50.901 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonInputFormatter: JSON input formatter threw an exception: The JSON value could not be converted to api.Dtos.MessagePing.CreateMessagePingRequestDto. Path: $ | LineNumber: 0 | BytePositionInLine: 127.
----
2024-06-21 12:20:50.902 +00:00 [Debug] Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder: Done attempting to bind parameter 'MessagePingDto' of type 'api.Dtos.MessagePing.CreateMessagePingRequestDto'.
2024-06-21 12:20:50.903 +00:00 [Debug] Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder: Done attempting to bind parameter 'MessagePingDto' of type 'api.Dtos.MessagePing.CreateMessagePingRequestDto'.
2024-06-21 12:20:50.903 +00:00 [Debug] Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder: Attempting to validate the bound parameter 'MessagePingDto' of type 'api.Dtos.MessagePing.CreateMessagePingRequestDto' ...
2024-06-21 12:20:50.903 +00:00 [Debug] Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder: Done attempting to validate the bound parameter 'MessagePingDto' of type 'api.Dtos.MessagePing.CreateMessagePingRequestDto'.
2024-06-21 12:20:50.905 +00:00 [Trace] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Action Filter: Before executing OnActionExecuting on filter Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter.
2024-06-21 12:20:50.905 +00:00 [Trace] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Action Filter: After executing OnActionExecuting on filter Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter.
2024-06-21 12:20:50.905 +00:00 [Trace] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Action Filter: Before executing OnActionExecuting on filter Microsoft.AspNetCore.Mvc.Infrastructure.ModelStateInvalidFilter.
2024-06-21 12:20:50.905 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Infrastructure.ModelStateInvalidFilter: The request has model state errors, returning an error response.
2024-06-21 12:20:50.905 +00:00 [Trace] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Action Filter: After executing OnActionExecuting on filter Microsoft.AspNetCore.Mvc.Infrastructure.ModelStateInvalidFilter.
2024-06-21 12:20:50.905 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Request was short circuited at action filter 'Microsoft.AspNetCore.Mvc.Infrastructure.ModelStateInvalidFilter'.
2024-06-21 12:20:50.905 +00:00 [Trace] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Action Filter: Before executing OnActionExecuted on filter Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter.
2024-06-21 12:20:50.905 +00:00 [Trace] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Action Filter: After executing OnActionExecuted on filter Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter.
2024-06-21 12:20:50.906 +00:00 [Trace] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Result Filter: Before executing OnResultExecuting on filter Microsoft.AspNetCore.Mvc.Infrastructure.ClientErrorResultFilter.
2024-06-21 12:20:50.906 +00:00 [Trace] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Result Filter: After executing OnResultExecuting on filter Microsoft.AspNetCore.Mvc.Infrastructure.ClientErrorResultFilter.
2024-06-21 12:20:50.906 +00:00 [Trace] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Before executing action result Microsoft.AspNetCore.Mvc.BadRequestObjectResult.
2024-06-21 12:20:50.906 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Infrastructure.DefaultOutputFormatterSelector: List of registered output formatters, in the following order: Microsoft.AspNetCore.Mvc.Formatters.HttpNoContentOutputFormatter, Microsoft.AspNetCore.Mvc.Formatters.StringOutputFormatter, Microsoft.AspNetCore.Mvc.Formatters.StreamOutputFormatter, Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter
2024-06-21 12:20:50.906 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Infrastructure.DefaultOutputFormatterSelector: Attempting to select an output formatter based on Accept header 'application/json, application/json' and explicitly specified content types 'Microsoft.AspNetCore.Mvc.Formatters.MediaTypeCollection'. The content types in the accept header must be a subset of the explicitly set content types.
2024-06-21 12:20:50.906 +00:00 [Debug] Microsoft.AspNetCore.Mvc.Infrastructure.DefaultOutputFormatterSelector: Selected output formatter 'Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter' and content type 'application/problem+json' to write the response.
2024-06-21 12:20:50.906 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor: Executing BadRequestObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ValidationProblemDetails'.
2024-06-21 12:20:50.906 +00:00 [Trace] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: After executing action result Microsoft.AspNetCore.Mvc.BadRequestObjectResult.
2024-06-21 12:20:50.906 +00:00 [Trace] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Result Filter: Before executing OnResultExecuted on filter Microsoft.AspNetCore.Mvc.Infrastructure.ClientErrorResultFilter.
2024-06-21 12:20:50.906 +00:00 [Trace] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Result Filter: After executing OnResultExecuted on filter Microsoft.AspNetCore.Mvc.Infrastructure.ClientErrorResultFilter.
2024-06-21 12:20:50.907 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Executed action api.Controllers.MessagePingController.Create (api) in 12.6443ms
2024-06-21 12:20:50.907 +00:00 [Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executed endpoint 'api.Controllers.MessagePingController.Create (api)'
2024-06-21 12:20:50.909 +00:00 [Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request finished HTTP/1.1 POST https://myazurewepapp.azurewebsites.net/ping - 400 - application/problem+json;+charset=utf-8 16.0021ms

I have marked the line I think is causing me trouble with —-
As I can understand the json I send from the app is somehow not formatted correctly so that the api can handle/format it to further process.
I have however tryed to test my api with reqbin.com, where I can succesfully send the exact same json which I send from the app. And I cannot figure out why not.
When i POST from reqbin the json is accepted and put into my sql database with out any trouble.

The GET api endpoint I have to receive the ping is like this:

{
    "type": "object",
    "properties": {
        "TimeOfPing": {
            "type": "string"
        },
        "SmartphoneId": {
            "type": "string"
        },
        "DeviceId": {
            "type": "string"
        },
        "ProcessNote": {
            "type": "string"
        }
    },
    "additionalProperties": false
}

I cannot identify any problems there.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật