I am pretty new to Haskell and I am not sure how I can achieve this. I am using wreq as HTTP client and I would like to check what HTTP headers are being sent to the server. For instance, I have defined the following method, which tries to authenticate using Facebook credentials:
authenticate ⦂ String → String → IO (Response ByteString)
authenticate facebookId facebookToken =
postWith opts "https://api.somedomain.com/auth" (object $ ["facebook_token" .= facebookToken, "facebook_id" .= facebookId])
where opts = defaults & header "Content-Type" .~ ["application/json"]
& header "Accept" .~ ["application/json"]
& proxy ?~ httpProxy "localhost" 9396
With POSTman I get the proper response but with wreq I get forbidden access (403). I assume some extra request headers might be added by the library and that's what I would like to check.
Any hints?
EDIT: An http proxy is now being used to check HTTP traffic (wreq requests are not detected though).
In Wreq, the Options type is an instance of Show, so you can pass it to print, or simply inspect it on ghci:
ghci> import Network.Wreq
ghci> defaults :: Options
Options { manager = Left _, proxy = Nothing, auth = Nothing, headers =
[("User-Agent","haskell wreq-0.3.0.1")], params = [], redirects = 10, cookies = [] }
You can also use the headers lens to focus directly on the headers:
ghci> defaults ^. headers
[("User-Agent","haskell wreq-0.3.0.1")]
But if Wreq is adding some headers after passing the options to postWith, you'll have to use a web debugging proxy like Fiddler to know what's going on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With