Reputation: 3940
Is there a way to request an URL and get the response as a string?
I've tried to use both the "Requests" package and "LibCURL" but I cant find a way to do this
Fx. if I use requests the error I receive looks like
get(url)
ERROR: MbedTLS error code -30592: SSL - A fatal alert message was received from our peer
in macro expansion at /home/david/.julia/v0.5/MbedTLS/src/error.jl:4 [inlined]
in handshake(::MbedTLS.SSLContext) at /home/david/.julia/v0.5/MbedTLS/src/ ssl.jl:145
in open_stream(::HttpCommon.Request, ::MbedTLS.SSLConfig, ::Float64, ::Nullable{URIParser.URI}, ::Nullable{URIParser.URI}) at /home/david/.julia/ v0.5/Requests/src/streaming.jl:209
in #do_stream_request#23(::Dict{AbstractString,AbstractString}, ::Void, ::Void, ::Void, ::Array{Requests.FileParam,1}, ::Void, ::Dict{Any,Any}, ::Bool, ::Int64, ::Array{HttpCommon.Response,1}, ::MbedTLS.SSLConfig, ::Bool, ::Bool, ::Bool, ::Nullable{URIParser.URI}, ::Nullable{URIParser.URI}, ::Requests.#do_stream_request, ::URIParser.URI, ::String) at /home/david/.julia /v0.5/Requests/src/Requests.jl:361
in do_stream_request(::URIParser.URI, ::String) at /home/david/.julia/v0.5/ Requests/src/Requests.jl:324
in #do_request#22(::Array{Any,1}, ::Function, ::URIParser.URI, ::String) at / home/david/.julia/v0.5/Requests/src/Requests.jl:291
in #get#29(::Array{Any,1}, ::Function, ::URIParser.URI) at /home/david/.julia/ v0.5/Requests/src/Requests.jl:424
in #get#28(::Array{Any,1}, ::Function, ::String) at /home/david/.julia/v0.5/ Requests/src/Requests.jl:423
in get(::String) at /home/david/.julia/v0.5/Requests/src/Requests.jl:423
Upvotes: 1
Views: 647
Reputation: 31342
You're looking for readall
with Requests (but in the future it may be moved to readstring
since readall
has been deprecated in Base Julia):
julia> using Requests
julia> readall(get("http://example.com"))
"<!doctype html>\n<html>\n<head> …
Upvotes: 3