Hi,
I’m trying to use CUrl
https://github.com/JetBrains/kotlin-native/blob/master/samples/libcurl/src/libcurlMain/kotlin/CUrl.kt for POST data
I’ve added SSL
curl_easy_setopt(curl, CURLOPT_PORT, 443L)
curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS)
and method POST
fun post(postData: String) {
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headersCRef)
val cstr = postData.cstr
curl_easy_setopt(curl, CURLOPT_POST, 1)
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, cstr)
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, cstr.size)
val res = curl_easy_perform(curl)
curl_slist_free_all(headersCRef)
if (res != CURLE_OK) {
throw RuntimeException("curl_easy_perform() failed: ${curl_easy_strerror(res)?.toKString()}")
}
}
But the server accepts wrong data - without some chars (at the start or at the end).
What I do wrong? How it can be fixed?
FIXED:
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, cstr)
->
_curl_easy_setopt_(curl, _CURLOPT_POSTFIELDS_, cstr.getPointer(MemScope()))