user3915521
user3915521

Reputation: 41

Groovy HTTPBuilder post file upload without multipart/form-data?

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

Upvotes: 4

Views: 9808

Answers (1)

cfrick
cfrick

Reputation: 37073

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
}

Upvotes: 5

Related Questions