Jump to content

Recommended Posts

Posted

I'd like to make Scala code to upload my dxp file to spetific Spotfire Library.

But with below code, I got 405 code.. is it not possile or I missed somthing?

<-- my scala code -->

val filepath = "d:/spotfire_sample.dxp"

val ServerURL = "11.90.11.123"

val port = 8555

val Library = "spotfire/wp/startPage#/libraryBrowser?id=5c0f525d-42ca-466c-acf8-02b9118ba6b5"; // don't know this Library address is correct

val Address = s"http://$ServerURL:$port/$Library"

val url = new URL(Address)

val connection = url.openConnection().asInstanceOf[HttpURLConnection]

val Credentials = java.util.Base64.getEncoder.encodeToString("seokjung.kim:12345678".getBytes)

connection.setRequestProperty("Authorization", s"Basic $Credentials")

connection.setRequestMethod("POST")

connection.setDoOutput(true);

connection.setRequestProperty("Content-Type", "application/octet-stream")

connection.setRequestProperty("Content-Disposition", "form-data; name="file"; filename="" + filepath + """)

val inputStream = new BufferedInputStream(new FileInputStream(filepath))

val outputStream = new DataOutputStream(connection.getOutputStream())

val buffer = new Array[byte](4096)

var bytesRead = -1

while ({bytesRead = inputStream.read(buffer); bytesRead != -1})

{

outputStream.write(buffer, 0, bytesRead)

}

inputStream.close()

outputStream.flush()

outputStream.close()

val response = connection.getResponseCode()

println("reponse : " + response) // always get 405 but when mehtod is chagned "GET" I got 200

connection.disconnect()

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...