0
我有一個用Groovy編寫的小型代理服務器,它記住用戶的請求,然後加載原始內容int SocketOutputStream。一切(html,js和css)加載正常 - 但圖片。所有二進制內容都從頁面中消失。如何將圖像加載到瀏覽器輸出流?
這裏是我的代碼:
int host = 3128
def address = Inet4Address.getByName("localhost")
def server = new ServerSocket(host, 25, address)
println "Appication strted on $address, $host"
while (true) {
server.accept() { socket ->
socket.withStreams {SocketInputStream input, SocketOutputStream output ->
def reader = input.newReader()
String buffer = reader.readLine()
params = buffer.split(' ')
String url = params[1]
URL contentUrl = new URL(url)
//Doing some hard work with requested content
output.withWriter { writer ->
writer << new URL(url).openStream()
}
}
}
}
也許有人cpould幫助我嗎? 謝謝。
感謝了很多人 - 真的幫助! –