This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
NeverCast's profile picture

http.get.readAll is returning malformed responses

Started by NeverCast, 07 January 2013 - 11:40 AM
NeverCast #1
Posted 07 January 2013 - 12:40 PM
Hello,

I'm making a package manager for my computers that uses raw.github.com as the source, however I currently have an issue with http requests.
When I request a url, instead of getting the expected plain text that I see in notepad or my web browser. I get a string where every character is suffixed or prefixed with a question mark.

Here is an example, https://raw.github.c...master/PACKAGES this path is my package list on my repo.
but when I request it with

http.get("https://raw.github.com/nevercast/CCNet/master/PACKAGES").readAll()

I get:

y?\?c?l?i?e?n?t?
?
?\?s?e?r?v?e?r?
?
?

instead of the expected output of

\client
\server

I do have a nice api that handles my repos, but without a working http api, it's useless.
Important information: I'm using the Web Applet, Subversion build: 32
theoriginalbit #2
Posted 07 January 2013 - 12:50 PM
try using http.request instead of get… use request when pulling down raw data from say github and pastebin. get and post for pages with php scripts and you want to post to that page.

example that i have used in my own Extended String Library:


http.request( url )
local event = nil
while true do
  event = { os.pullEventRaw() }
  if (event[1] == "http_success") then
	break
  elseif (event[1] == "http_failure") then
	error( "No response from server.", 2 )
  end
end

return event[3].readAll()
Edited on 07 January 2013 - 11:51 AM
NeverCast #3
Posted 07 January 2013 - 12:54 PM
Thanks TheOriginalBIT, I'll give that a go and submit an update.


Edit: Update,

No luck, I extended the http api with a get2 function and implemented that code, minus the readAll() at the end of event[3] so it would function like get does, saving me having to change anything else in my code.

It still returns the same result, question marks in the response body.
It's almost like it's reading it as UTF16 instead of UTF8
NeverCast #4
Posted 07 January 2013 - 03:48 PM
Fixed, it was a UTF16 encoding issue with the files I uploaded to GitHub, my update script was spitting out the wrong encoding.
immibis #5
Posted 07 January 2013 - 07:36 PM
try using http.request instead of get… use request when pulling down raw data from say github and pastebin. get and post for pages with php scripts and you want to post to that page.

example that i have used in my own Extended String Library:


http.request( url )
local event = nil
while true do
  event = { os.pullEventRaw() }
  if (event[1] == "http_success") then
	break
  elseif (event[1] == "http_failure") then
	error( "No response from server.", 2 )
  end
end

return event[3].readAll()
That's what http.get does.
theoriginalbit #6
Posted 07 January 2013 - 07:47 PM
Yeh I was having similar issues with get though. I've had no issues with request.