# Trouble Sending HTTP Requests to Port 443 (HTTPS) using Sockets.jl

**URL:** <https://discourse.julialang.org/t/trouble-sending-http-requests-to-port-443-https-using-sockets-jl/97998>\
**Category:** General Usage\
**Tags:** sockets, https\
**Created:** [April 27, 2023, 2:37pm UTC](https://discourse.julialang.org/t/trouble-sending-http-requests-to-port-443-https-using-sockets-jl/97998 "2023-04-27T14:37:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheDude](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@TheDude](https://discourse.julialang.org/u/TheDude)\
**Post date:** [April 27, 2023, 2:37pm UTC](https://discourse.julialang.org/t/trouble-sending-http-requests-to-port-443-https-using-sockets-jl/97998/1 "2023-04-27T14:37:17Z")

</div>

Trying to send HTTP requests using the Sockets.jl package. It works on port 80 say for “[example.com](http://example.com)” but any attempt to contact a server at port 443 (HTTPS) I’m met with a - 400 Bad Request - The plain HTTP request was sent to HTTPS port. I’m kind a network security n00b but I suspect there’s some SSL handshake that needs to happen under the hood and I don’t see how to inspect that, if that’s even the problem. Example code below with subsequent error…

```julia
using Sockets

conn = connect("git-scm.com",443)

@async while isopen(conn)
    write(stdout, read(conn, Char))
end

query = "GET / HTTP/1.1
Host: git-scm.com
Accept: text/html

"
write(conn,query)

```

```julia
julia> HTTP/1.1 400 Bad Request
Server: cloudflare
Date: Thu, 27 Apr 2023 14:27:43 GMT
Content-Type: text/html
Content-Length: 253
Xonnection: close
CF-RAY: -
Connection: Keep-Alive

<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>cloudflare</center>
</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![AMJ](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amj/32/214096_2.png) [@AMJ](https://discourse.julialang.org/u/AMJ)\
**Post date:** [April 27, 2023, 2:43pm UTC](https://discourse.julialang.org/t/trouble-sending-http-requests-to-port-443-https-using-sockets-jl/97998/2 "2023-04-27T14:43:48Z")

</div>

Have you tried [OpenSSL.jl](https://github.com/JuliaWeb/OpenSSL.jl) or [MbedTLS.jl](https://github.com/JuliaLang/MbedTLS.jl) ?

---

<div class="post-metadata">

**Author:** ![TheDude](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@TheDude](https://discourse.julialang.org/u/TheDude)\
**Post date:** [April 27, 2023, 2:53pm UTC](https://discourse.julialang.org/t/trouble-sending-http-requests-to-port-443-https-using-sockets-jl/97998/3 "2023-04-27T14:53:44Z")

</div>

I’ve been looking at MBedTLS.jl while making this post, but are we saying that the Sockets.jl package can’t handle this use case on its own? No problem if so, but I wanted to probe the community to see if that’s the case and to understand a solution otherwise if it can be handled natively.

Thank you for the response btw! Hope to hear more from you and others!

---

<div class="post-metadata">

**Author:** ![AMJ](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amj/32/214096_2.png) [@AMJ](https://discourse.julialang.org/u/AMJ)\
**Post date:** [April 27, 2023, 3:00pm UTC](https://discourse.julialang.org/t/trouble-sending-http-requests-to-port-443-https-using-sockets-jl/97998/4 "2023-04-27T15:00:37Z")

</div>

Writing a native TLS encryption would be too much work. For now using and building over already battle tested available packages from other languages is a safe bet.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [April 27, 2023, 4:05pm UTC](https://discourse.julialang.org/t/trouble-sending-http-requests-to-port-443-https-using-sockets-jl/97998/5 "2023-04-27T16:05:59Z")

</div>

I’d recommend using HTTP.jl. The Sockets stdlib is just a literal socket library for TCP/UDP/other sockets. HTTP/S is a protocol, it per se is unrelated to sockets.

---

<div class="post-metadata">

**Author:** ![AMJ](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amj/32/214096_2.png) [@AMJ](https://discourse.julialang.org/u/AMJ)\
**Post date:** [April 27, 2023, 4:41pm UTC](https://discourse.julialang.org/t/trouble-sending-http-requests-to-port-443-https-using-sockets-jl/97998/6 "2023-04-27T16:41:37Z")

</div>

If one needs to use allocation free persistent communication, HTTP.jl would not be much of a help there, one would need to use Sockets, unsafe\_write (with [this](https://github.com/JuliaLang/julia/pull/49125) modification) to avoid allocation in the hot loop.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [April 27, 2023, 8:19pm UTC](https://discourse.julialang.org/t/trouble-sending-http-requests-to-port-443-https-using-sockets-jl/97998/7 "2023-04-27T20:19:51Z")

</div>

Ok, but for the simple case of “use HTTPS to connect to a webserver”, HTTP.jl is perfectly fine.
