Web services java.io.IOException:无法在Play Framework中的通道java.nio.channels.SocketChannel上写入
我正试图上传一个字节数组到一个远程WS,其中包含多部分/表单数据!使用Scala的框架。我的代码是:Web services java.io.IOException:无法在Play Framework中的通道java.nio.channels.SocketChannel上写入,web-services,scala,playframework-2.2,asynchttpclient,Web Services,Scala,Playframework 2.2,Asynchttpclient,我正试图上传一个字节数组到一个远程WS,其中包含多部分/表单数据!使用Scala的框架。我的代码是: //create byte array from file val myFile = new File(pathName) val in = new FileInputStream(myFile) val myByteArray = new Array[Byte](audioFile.length.toInt) in.read(audioByteArray
//create byte array from file
val myFile = new File(pathName)
val in = new FileInputStream(myFile)
val myByteArray = new Array[Byte](audioFile.length.toInt)
in.read(audioByteArray)
in.close()
// create parts
val langPart = new StringPart("lang", "pt")
val taskPart = new StringPart("task","echo")
val audioPart = new ByteArrayPart("sbytes", "myFilename", myByteArray, "default/binary", "UTF-8")
val client: AsyncHttpClient = WS.client
val request = client.preparePost(RemoteWS)
.addHeader("Content-Type", "multipart/form-data")
.addBodyPart(audioPart)
.addBodyPart(taskPart)
.addBodyPart(langPart).build()
val result = Promise[Response]()
// execute request
client.executeRequest(request, new AsyncCompletionHandler[AHCResponse]{
override def onCompleted(response: AHCResponse): AHCResponse = {
result.success(Response(response))
response
}
override def onThrowable(t: Throwable) {
result.failure(t)
}
})
// handle async response
result.future.map(result =>{
Logger.debug("response: " + result.getAHCResponse.getResponseBody("UTF-8"))
})
每次我执行此请求时,它都会引发以下异常:
java.io.IOException:无法在通道java.nio.channels.SocketChannel上写入
远程服务器正常,我可以使用例如Postman发出成功的请求
我正在使用Play Framework:
播放2.2.3,使用运行Java 1.8.0的Scala 2.10.3构建
AsyncHttpClient的版本:
com.ning:异步http客户端:1.7.18
欢迎任何帮助 你好,我有同样的问题,你是如何解决的?