HttpRequest

case
class HttpRequest(url: String, method: String, connectFunc: HttpExec, params: Seq[(String, String)], headers: Seq[(String, String)], options: Seq[HttpOption], proxyConfig: Option[Proxy], charset: String, sendBufferSize: Int, urlBuilder: HttpRequest => String, compress: Boolean, digestCreds: Option[(String, String)])

Immutable builder for creating an http request

This is the workhorse of the scalaj-http library.

You shouldn't need to construct this manually. Use scalaj.http.Http.apply to get an instance

The params, headers and options methods are all additive. They will always add things to the request. If you want to replace those things completely, you can do something like

.copy(params=newparams)
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any

Value members

Concrete methods

def asBytes: HttpResponse[Array[Byte]]

Execute this request and parse http body as Array[Byte]

Execute this request and parse http body as Array[Byte]

def asParamMap: HttpResponse[Map[String, String]]

Execute this request and parse http body as query string key-value pairs

Execute this request and parse http body as query string key-value pairs

def asParams: HttpResponse[Seq[(String, String)]]

Execute this request and parse http body as query string key-value pairs

Execute this request and parse http body as query string key-value pairs

def asString: HttpResponse[String]

Execute this request and parse http body as String using server charset or configured charset

Execute this request and parse http body as String using server charset or configured charset

Execute this request and parse http body as a querystring containing oauth_token and oauth_token_secret tupple

Execute this request and parse http body as a querystring containing oauth_token and oauth_token_secret tupple

def auth(user: String, password: String): HttpRequest

Add a standard basic authorization header

Add a standard basic authorization header

def charset(cs: String): HttpRequest

Change the charset used to encode the request and decode the response. UTF-8 by default

Change the charset used to encode the request and decode the response. UTF-8 by default

def compress(c: Boolean): HttpRequest

Should HTTP compression be used If true, Accept-Encoding: gzip,deflate will be sent with request. If the server response with Content-Encoding: (gzip|deflate) the client will automatically handle decompression

Should HTTP compression be used If true, Accept-Encoding: gzip,deflate will be sent with request. If the server response with Content-Encoding: (gzip|deflate) the client will automatically handle decompression

This is on by default

Value Params
c

should compress

def cookies(cks: Seq[HttpCookie]): HttpRequest

Add multiple cookies to the request. Usefull for round tripping cookies from HttpResponse.cookies

Add multiple cookies to the request. Usefull for round tripping cookies from HttpResponse.cookies

def digestAuth(user: String, password: String): HttpRequest

Add digest authentication credentials

Add digest authentication credentials

def exec[T](parser: (Int, Map[String, IndexedSeq[String]], InputStream) => T): HttpResponse[T]

Executes this request

Executes this request

This is a power user method for parsing the response body. The parser function will be passed the response code, response headers and the InputStream

Type Params
T

the type returned by the input stream parser

Value Params
parser

function to process the response body InputStream

def execute[T](parser: InputStream => T): HttpResponse[T]

Executes this request

Executes this request

Keep in mind that if you're parsing the response to something other than String, you may hit parsing error if the server responds with a different content type for error cases.

Type Params
T

the type returned by the input stream parser

Value Params
parser

function to process the response body InputStream. Will be used for all response codes

def header(key: String, value: String): HttpRequest

Add a http header to the request

Add a http header to the request

def headers(h: Map[String, String]): HttpRequest

Add http headers to the request

Add http headers to the request

def headers(h: Seq[(String, String)]): HttpRequest

Add http headers to the request

Add http headers to the request

def headers(h: (String, String), rest: (String, String)*): HttpRequest

Add http headers to the request

Add http headers to the request

def method(m: String): HttpRequest

Change the http request method. The library will allow you to set this to whatever you want. If you want to do a POST, just use the postData, postForm, or postMulti methods. If you want to setup your request as a form, data or multi request, but want to change the method type, call this method after the post method:

Change the http request method. The library will allow you to set this to whatever you want. If you want to do a POST, just use the postData, postForm, or postMulti methods. If you want to setup your request as a form, data or multi request, but want to change the method type, call this method after the post method:

Http(url).postData(dataBytes).method("PUT").asString
def oauth(consumer: Token): HttpRequest

OAuth v1 sign the request with the consumer token

OAuth v1 sign the request with the consumer token

def oauth(consumer: Token, token: Token): HttpRequest

OAuth v1 sign the request with with both the consumer and client token

OAuth v1 sign the request with with both the consumer and client token

def oauth(consumer: Token, token: Token, verifier: String): HttpRequest

OAuth v1 sign the request with with both the consumer and client token and a verifier

OAuth v1 sign the request with with both the consumer and client token and a verifier

def oauth(consumer: Token, token: Option[Token], verifier: Option[String]): HttpRequest

OAuth v1 sign the request with with both the consumer and client token and a verifier

OAuth v1 sign the request with with both the consumer and client token and a verifier

Entry point for modifying the java.net.HttpURLConnection before the request is executed

Entry point for modifying the java.net.HttpURLConnection before the request is executed

Entry point for modifying the java.net.HttpURLConnection before the request is executed

Entry point for modifying the java.net.HttpURLConnection before the request is executed

Entry point for modifying the java.net.HttpURLConnection before the request is executed

Entry point for modifying the java.net.HttpURLConnection before the request is executed

def param(key: String, value: String): HttpRequest

Add a param to the GET querystring or POST form request

Add a param to the GET querystring or POST form request

def params(p: Map[String, String]): HttpRequest

Add params to the GET querystring or POST form request

Add params to the GET querystring or POST form request

def params(p: Seq[(String, String)]): HttpRequest

Add params to the GET querystring or POST form request

Add params to the GET querystring or POST form request

def params(p: (String, String), rest: (String, String)*): HttpRequest

Add params to the GET querystring or POST form request

Add params to the GET querystring or POST form request

def postData(data: String): HttpRequest

Raw data POST request. String bytes written out using configured charset

Raw data POST request. String bytes written out using configured charset

def postData(data: Array[Byte]): HttpRequest

Raw byte data POST request

Raw byte data POST request

Standard form POST request

Standard form POST request

def postForm(params: Seq[(String, String)]): HttpRequest

Standard form POST request and set some parameters. Same as .postForm.params(params)

Standard form POST request and set some parameters. Same as .postForm.params(params)

Multipart POST request.

Multipart POST request.

This is probably what you want if you need to upload a mix of form data and binary data (like a photo)

def proxy(host: String, port: Int): HttpRequest

Send request via a standard http proxy

Send request via a standard http proxy

def proxy(host: String, port: Int, proxyType: Type): HttpRequest

Send request via a proxy. You choose the type (HTTP or SOCKS)

Send request via a proxy. You choose the type (HTTP or SOCKS)

def proxy(proxy: Proxy): HttpRequest

Send request via a proxy

Send request via a proxy

def proxyAuth(user: String, password: String): HttpRequest

Add a proxy basic authorization header

Add a proxy basic authorization header

def put(data: String): HttpRequest

Raw data PUT request. String bytes written out using configured charset

Raw data PUT request. String bytes written out using configured charset

def put(data: Array[Byte]): HttpRequest

Raw byte data PUT request

Raw byte data PUT request

def sendBufferSize(numBytes: Int): HttpRequest

The buffer size to use when sending Multipart posts

The buffer size to use when sending Multipart posts

def timeout(connTimeoutMs: Int, readTimeoutMs: Int): HttpRequest

The socket connection and read timeouts in milliseconds. Defaults are 1000 and 5000 respectively

The socket connection and read timeouts in milliseconds. Defaults are 1000 and 5000 respectively

Inherited methods

def productElementNames: Iterator[String]
Inherited from
Product
def productIterator: Iterator[Any]
Inherited from
Product