mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
Add docs on manually following redirection.
This commit is contained in:
parent
1ce9a466f1
commit
e10e3d9da8
1 changed files with 32 additions and 0 deletions
32
README.md
32
README.md
|
@ -177,6 +177,38 @@ end
|
|||
➔ 404 Resource Not Found | text/html 282 bytes
|
||||
```
|
||||
|
||||
### Manually following redirection
|
||||
|
||||
To disable automatic redirection, set `:max_redirects => 0`.
|
||||
|
||||
```ruby
|
||||
>> RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1')
|
||||
=> RestClient::Response 200 "{\n "args":..."
|
||||
|
||||
>> RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1', max_redirects: 0)
|
||||
RestClient::Found: 302 Found
|
||||
```
|
||||
|
||||
To manually follow redirection, you can call `Response#follow_redirection`. Or
|
||||
you could of course inspect the result and choose custom behavior.
|
||||
|
||||
```ruby
|
||||
>> RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1', max_redirects: 0)
|
||||
RestClient::Found: 302 Found
|
||||
>> begin
|
||||
RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1', max_redirects: 0)
|
||||
rescue RestClient::ExceptionWithResponse => err
|
||||
end
|
||||
>> err
|
||||
=> #<RestClient::Found: 302 Found>
|
||||
>> err.response
|
||||
=> RestClient::Response 302 "<!DOCTYPE H..."
|
||||
>> err.response.headers[:location]
|
||||
=> "/get"
|
||||
>> err.response.follow_redirection
|
||||
=> RestClient::Response 200 "{\n "args":..."
|
||||
```
|
||||
|
||||
## Result handling
|
||||
|
||||
The result of a `RestClient::Request` is a `RestClient::Response` object.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue