This is not a bug. I think it’s just not clear how to use Lua socket and http requests.
First, you need to add a forward slash after .com and before your ?. This is why the host is not found. After doing this you should see the file in your Documents directory containing the web page content.
Try changing sink = ltn12.sink.file(myFile) to sink = ltn12.sink.file(io.stdout). This will print the output to the terminal. Make sure you open the simulator using Corona Terminal. This is a good way to verify your data is coming through.
To show something in the ui popup I’d recommend reading that from the file that gets saved in the Documents directory, using something like:
local content = io.open(path, “r”)
I think you’re getting a “1” as the content of your http.request because it’s the first value passed back in the headers, not the content itself. You have to take a few more steps to get content, such as what I recommend above–read it from the file that gets saved out as a result of the request.
I added the forward slash where you suggested and I get this when I put io.stdout instead of myFile (Which is open). When I leave my file pointer in there it puts blank into it. If i use google however, it still puts the correct content in that file.
Sorry I didn’t include any code in my last message. I was on my iPhone, moving between modes of transportation.
Try this code. I rewrote some of the stuff in your code:
local http = require("socket.http")
local ltn12 = require("ltn12")
--the url needed a forward slash ( / ) after unicornlabs.com
myUrl = "http://ws.unicornlabs.com/?hk=9871&appId=1350&udid=000&service=launchAd"
--native.setActivityIndicator(true)
local path = system.pathForFile( "mos.content", system.DocumentsDirectory )
local myFile = io.open( path, "w+b" )
--Check for a connection to the host
r, c, h = http.request{
method = "HEAD",
url = myUrl
}
local hostFound = false
if c == 200 then
print("host found!")
hostFound = true
else
print("host not found")
end
--If a connection with the host was found, get the content
if hostFound then
http.request{
url = myUrl,
sink = ltn12.sink.file(myFile)
-- sink = ltn12.sink.file(io.stdout)
}
--Open the file containing the content we received
local file = io.open(path, "r")
local content = file:read("\*a")
--Show the content in the terminal
print(content)
--Show the content
native.showAlert(content,content)
end
I added a few lines to check the page headers just to see if a connection to the host was made. If a connection is made, then the script can go on and get the content. It gets the content, puts it in a file (which is what sink does in the http.request), and then it reads the content from the file and shows it in the alert.
Notice I also commented out activity indicator. If you look at the documentation, API Reference p.42, you’ll notice that the activity indicator doesn’t actually come up until the end of your script. So I think it was coming up even after you made a connection and got your content and then it was not going away. A way to get this to work might be to use an event listener to initiate the connecting to the server and getting the content. This way the whole script can run first and then when it’s done the event listener kicks in the connection. See p.56 in the API Reference for some examples of event listeners.
Lastly, the content you’re grabbing from the web has html table tags, image tags, and other formatting. You won’t be able to display these in the alert. But you probably already know that.
it works, thanks a ton! Now last question I have is that i am putting this content into a webpopup, is there any way to rotate the webpopup based on current rotation? i don’t want to rotate anything else on the screen (entire app) just the webpopup. thanks! [import]uid: 6317 topic_id: 1109 reply_id: 2848[/import]
I had tried modifying build.settings file with these type of settings, but the webpopup for some reason does not rotate when i rotate the ipad. Is this iphone only? [import]uid: 6317 topic_id: 1109 reply_id: 2853[/import]
yeah this is a huge hinderance, if any of the devs are reading is this on the “to work on” list for next beta? would be HUGELY useful! Thanks! [import]uid: 6317 topic_id: 1109 reply_id: 2856[/import]
we have seen it and wanted to use it, but can’t because it doesn’t rotate when the orientation is changing. And handling orientation for at least 2 of them is basically mandatory these days in the app store. And that goes even more for the IPad.
Michael [import]uid: 5712 topic_id: 1109 reply_id: 2863[/import]
Can you just destroy the webpopup on an orientation change and recreate it in the new orientation?
The guideline for iPad is that if you run in landscape, you should generally try to support BOTH landscape modes (and the same for portrait); the idea is that the app should work in the direction the user is currently holding the device. But in most cases the user is not going to be rotating the device by 180 degrees very often in a given session, so even if there’s a momentary lag when recreating the ad banner upside-down, it may be acceptable? (I haven’t tested this.) [import]uid: 3007 topic_id: 1109 reply_id: 3024[/import]