Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kotlin-mpp-wininet - Cookie Handle #1

Open
carlosrafp opened this issue Oct 23, 2020 · 4 comments
Open

kotlin-mpp-wininet - Cookie Handle #1

carlosrafp opened this issue Oct 23, 2020 · 4 comments

Comments

@carlosrafp
Copy link

how to get the cookie returned by a Http get?

@vaclavhodek
Copy link
Member

You have to use HttpQueryInfoW with HTTP_QUERY_COOKIE to get the corresponding header.

There's no built-in solution for handling cookies out-of-the-box. The same applies for setting cookies. You need to send Set-Cookie header manually.

@carlosrafp
Copy link
Author

carlosrafp commented Oct 23, 2020

Ty, HttpQueryInfoW worked fine for me,

justed added this code in "WinInetHelper.request", after getResponseData() call

sample:
var lpszData = ByteArray(200)
val dwSize = alloc()
val index = alloc()
index.value = 0.dword()
dwSize.value = 200.dword()
lpszData.usePinned {
if (HttpQueryInfoW(requestHandle.handle,HTTP_QUERY_SET_COOKIE,it.addressOf(0),dwSize.ptr,index.ptr) == 0){
if (GetLastError().toInt() == ERROR_INSUFFICIENT_BUFFER){
println("ERROR_INSUFFICIENT_BUFFER, required_size = " + dwSize.value)
lpszData = ByteArray(dwSize.value.toInt())
index.value = 0.dword()
HttpQueryInfoW(requestHandle.handle,HTTP_QUERY_SET_COOKIE,it.addressOf(0),dwSize.ptr,index.ptr)
}
else if (GetLastError().toInt() == ERROR_HTTP_HEADER_NOT_FOUND){
index.value = 0.dword()
HttpQueryInfoW(requestHandle.handle,HTTP_QUERY_COOKIE,it.addressOf(0),dwSize.ptr,index.ptr)
println("ERROR_HTTP_HEADER_NOT_FOUND (HTTP_QUERY_SET_COOKIE) - trying HTTP_QUERY_COOKIE")
}
}
}
println("size = " + dwSize.value + ", indice = " + index.value + ", cookie = " + lpszData.decodeToString())

@carlosrafp
Copy link
Author

Do you Know to to handle https with certificate? In java u should update sdk cacerts, no idea how to do it in klotin/native

@vaclavhodek
Copy link
Member

HTTPS is supported by the WinInet library and handled transparently, so the certificate has to be available in system.

It's controller by INTERNET_FLAG_SECURE flag. Check MemScope.openRequest(...) function in WinInetHelper.kt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants