Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Xylem

Request and read from a HTTPS website

Question

So i started messing about with the internet card, i can get onto google just fine as long as i use http with port 80. But when i try to use anything with a https and port 443 i can't get anything. I keep getting an invalid port or url address. Im pretty sure my address is right but i think my port might be wrong

Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0

What did you run? Was it require("internet").request("https://google.com:443"), or require("internet").connect("https://google.com:443"), or require("component").internet.request("https://google.com:443"), or require("component").internet.connect("https://google.com:443"), or what?

Link to post
Share on other sites
  • 0
  • Solution

Yes, that's right. internet.open creates a TCP socket. They are useful when you need to communicate with a non-HTTP server (you probably know things like SSH, FTP -- those are all non-HTTP protocols).

But when you want to send a request to an HTTP server, you need to use internet.request. It's a nice wrapper for component.internet.request that allows to interate over the response body. Like this:

local inet = require("internet")

local response = inet.request("https://google.com")
local body = ""
for chunk in response do
  body = body .. chunk
end

print(body)

Chunk is a small piece of response, one, maybe a few (I can't remember) kilobytes in size, or even empty. If a connection problem occurs, an error is thrown.

No one forbids you to use sockets to connect to an HTTP server. I do that in my simple http library. But that is slow and requires a TLS library with many dependencies when you want to use HTTPS. It can be useful (you can set the request method and control exactly what happens during the connection), although I recommend to use internet.request.

And, finally, internet.request supports HTTP and HTTPS.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.