Answer the question
In order to leave comments, you need to log in
POST request to a private API (has been blocked by CORS policy)??
Is it possible to connect to a closed API?
The resource accepts requests only from its own address, how can I get around this?
Change request headers?
Possible implementation in Java or kotlin
fun test(): Any? {
var link = "http://index.php"
val url = URL(link)
val con = url.openConnection() as HttpURLConnection
con.requestMethod = "POST"
con.setRequestProperty("Content-Type", "application/json")
con.doOutput = true
val out = DataOutputStream(con.outputStream)
out.writeBytes("q=preschool")
out.flush()
out.close()
BufferedReader(InputStreamReader(con.inputStream)).use {
val response = StringBuffer()
var inputLine = it.readLine()
while (inputLine != null) {
response.append(inputLine)
inputLine = it.readLine()
}
it.close()
println("Response : $response")
return response
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question