4

How do I perform an HTTP post in groovy using HTTPBuilder that uploads the raw bytes of a file without using multipart/form-data? Specifically, I want my request to look like this:

POST http://....
Host: myhost
Content-Length: numBytes
Proxy-Connection: Keep-Alive

Raw Data
Chris Snow
  • 23,813
  • 35
  • 144
  • 309
user3915521
  • 41
  • 1
  • 2

1 Answers1

5

you could send it as binary

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
def http = new HTTPBuilder('http://localhost:8080')
http.post(path:'/', body: new File('/etc/passwd').bytes, requestContentType: BINARY) { response ->
    println response.statusLine
}
cfrick
  • 35,203
  • 6
  • 56
  • 68