Author Topic: TCPObject GET requests  (Read 2285 times)

I am trying to make a little tcpobject thingy but I'm getting odd results.

This is the code I am using:
Code: [Select]
function Downloader::onDNSResolved(%this)
{
      echo("DNS Resolved");
}

function Downloader::onDNSFailed(%this)
{
      echo("DNS Failed");
}

function Downloader::onConnected(%this)
{
      echo("Connected");
      %req = "GET "@$file@" HTTP/1.0\nHost: "@$ip@"\n\n";
      echo(%req);
      %this.send(%req);
}

function Downloader::onConnectFailed(%this)
{
      echo("Connection Failed");
}

 

function Downloader::onDisconnect(%this)
{
      echo("Disconnected");
}
function Downloader::onLine(%this, %line)
{
      echo("TCP: " @ %line);
}
if(isobject(Downloader))
      Downloader.delete();
new tcpobject(Downloader)

I am then putting this in the console:
Code: [Select]
$ip = "98.227.200.17";
$file = "/shares/USB_Storage/testdoc.txt";
Downloader.connect("98.227.200.17:80");

And it fails to retrieve the file: http://98.227.200.17/shares/USB_Storage/testdoc.txt


I tried a similar test using dropbox: http://dl.dropbox.com/u/20459676/BuildBot%20Changelog.txt
Code: [Select]
$file = "/u/20459676/BuildBot%20Changelog.txt";
$ip = "dl.dropbox.com";
Downloader.connect("dl.dropbox.com:80");

And it worked fine.
What is going on here?  Is it the difference between how dropbox will simply display the text through the internet if you click the link versus my router will make you download it?


new HTTPObject(blah);
blah.get("brianhosting.net:80","/index.html");
function blah::onLine(%this,%line)
{
echo(%line);
}

worked.
FIXED
« Last Edit: March 07, 2012, 05:35:14 PM by Brian Smithers »

ok so I tried Brian's method and I got a 401 unauthorized.

Can anyone else click the link I provided or is it just me that can access it?

Also I would still kinda like to know why the TCP was being a bother and how to account for the fact that the url linked to a download request instead of displaying the document.


fixed
woops

What did you fix?  The / before index?  I must have not noticed you didn't include that, because I had it anyway.

I am still getting a 401 error, can anyone confirm that the link is accessable or not?

Edit:  it seems that you need a username/password to connect to the ip, but you do not for http://98.227.200.17/shares/

I guess the initial connect request will fail because it needs to connect to the domain before anything else.

How can I make it connect to /shares/ ?

Now I am trying this:
Code: [Select]
dlr.get("http://98.227.200.17/shares:80", "/USB_Storage/testdoc.txt");
but it calls onDNSFailed after about a second or two
« Last Edit: March 07, 2012, 06:20:07 PM by Nexus »

thats because  the first arg is what your connecting to (the IP) and the second is the file.

Now I am trying this:
Code: [Select]
dlr.get("http://98.227.200.17/shares:80", "/USB_Storage/testdoc.txt");
but it calls onDNSFailed after about a second or two
Try removing the http:// part.

Try removing the http:// part.

I have tried it both ways
without just makes the DNS error come sooner for some reason

Code: [Select]
dlr.get("98.227.200.17:80", "/shares/USB_Storage/testdoc.txt");
try that

heres an example

function getMasterList()
{
   if(!isObject(BLMasterList))
      new HTTPObject(BLMasterList);
   BLMasterList.get("master2.blockland.us:80","/");
}
-lesnip-
function BLMasterList::onLine(%this,%line)
{
   if(firstWord(%line) $= "FIELDS" || firstWord(%line) $= "START" || firstWord(%line) $= "END")
      return;
   echo(serverHostFromList(%line) @ "'s "@ serverNameFromList(%line) @ " [P: " @ serverPlayersFromList(%line) @ " B: " @ serverBricksFromList(%line) @ " M: " @ serverMapFromList(%line) @ " P/D: " @ serverGetPassDediFromList(%line) @ " IP: " @ serverGetIPPortFromList(%line) @ "]");
}

done.

try that

That was the first thing I tried.

Problem:  I cannot connect to the ip address directly, it HAS to be through the /shares/ url, otherwise it is a 401 unauthorized
I do not think httpobjects have the ability to connect to the /shares/ url

And your code assumes that the data being returned is direct text, and not a download.  I'm still unsure how to handle that.

That was the first thing I tried.

Problem:  I cannot connect to the ip address directly, it HAS to be through the /shares/ url, otherwise it is a 401 unauthorized
I do not think httpobjects have the ability to connect to the /shares/ url

And your code assumes that the data being returned is direct text, and not a download.  I'm still unsure how to handle that.
Support_Downloader.cs
In BlockOS

Problem:  I cannot connect to the ip address directly, it HAS to be through the /shares/ url, otherwise it is a 401 unauthorized
I do not think httpobjects have the ability to connect to the /shares/ url

It is absolutely impossible to "connect" to a path on a remote server. If it seems to the user this way, the server may be checking certain headers such as Referrer and Host in order to find some verification details. Some more information about the server software you're trying to interface with may help further, too.

EDIT: After some research, I've gotten to the conclusion that "connecting through" the /shares URL (which is absolutely impossible) is not necessary to fetch the file. Your issue is elsewhere.
« Last Edit: March 08, 2012, 01:32:50 AM by Port »

It is absolutely impossible to "connect" to a path on a remote server. If it seems to the user this way, the server may be checking certain headers such as Referrer and Host in order to find some verification details. Some more information about the server software you're trying to interface with may help further, too.

EDIT: After some research, I've gotten to the conclusion that "connecting through" the /shares URL (which is absolutely impossible) is not necessary to fetch the file. Your issue is elsewhere.

My hunch is that it has something to do with how clicking the link wont just display the text throuhg the internet, but will instead send you a download save/open thing.  I have no idea how to handle that, because Brian's BlockOS downloader still has the same problem.

My hunch is that it has something to do with how clicking the link wont just display the text throuhg the internet, but will instead send you a download save/open thing.  I have no idea how to handle that, because Brian's BlockOS downloader still has the same problem.
Your web server is incorrectly serving MIME types and not recognizing the .txt file as a form of plain text, hence it sends it as a binary stream. Not sure why it's giving you an auth error when I can expect the site just fine and all of it's headers seem to be fine. I'm going to guess that it might have to do with the headers Torque is sending it, possibly the Torque user-agent or lack of it.