<div dir="ltr">Hi Mike,<div><br></div><div>First, if you don't know how wreq acts when it gets invalid url – I suggest just launching repl and checking that out. I'll show how to do that using <a href="https://github.com/commercialhaskell/stack">haskell stack tool</a>:</div><div><br></div><div><div>➜ ~ stack install wreq</div><div>...</div><div>➜ ~ stack ghci</div><div>Run from outside a project, using implicit global config</div><div>Using resolver: lts-3.5 from global config file: /Users/kb/.stack/global/stack.yaml</div><div>Configuring GHCi with the following packages:</div><div>GHCi, version 7.10.2: <a href="http://www.haskell.org/ghc/">http://www.haskell.org/ghc/</a> :? for help</div><div>λ import Network.Wreq</div><div>λ get "nonvalid"</div><div>*** Exception: InvalidUrlException "nonvalid" "Invalid URL"</div></div><div><br></div><div>You see, it throws InvalidUrlException upon request, which you can catch and render an error.</div><div><br></div><div>Now, to get content, as per tutorial, just do:</div><div>λ import Control.Lens<br></div><div>λ res <- get "<a href="http://i.imgur.com/f0IKpky.png">http://i.imgur.com/f0IKpky.png</a>"<br></div><div><div>λ res ^. responseBody<br></div></div><div>... (long binary response goes into your output) ...</div><div><br></div><div>That's it. Last thing I should mention – errors which can be thrown are all just HttpException type. <a href="http://hackage.haskell.org/package/http-client-0.4.24/docs/Network-HTTP-Client.html#t:HttpException">Go and see possible ones</a>, some of which you might want to handle specifically, while others just in a generic "something bad happened" error.</div><div><br></div><div>Hope this helps.</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 4, 2015 at 6:18 PM, Mike Houghton <span dir="ltr"><<a href="mailto:mike_k_houghton@yahoo.co.uk" target="_blank">mike_k_houghton@yahoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
Please can someone explain how,using the wreq package, I can download and save a binary file?<br>
Say the file is at the end of<br>
<a href="http://x.y.z/files/myfile.jpg" rel="noreferrer" target="_blank">http://x.y.z/files/myfile.jpg</a><br>
<br>
and it is a jpeg and no authentication is needed.<br>
<br>
I just want to<br>
<br>
1. Check that the URL is syntactically correct - flag and error if not<br>
2. If the URL is syntactically ok then download the file using GET.<br>
3. Check that the response code is 200 and if so save the file<br>
3a. if the response code is not 200 then delegate to an error handling function or some simple idiomatic way of error handling.<br>
<br>
<br>
Thanks once again.<br>
<br>
Mike<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>