Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can this be done?

Status
Not open for further replies.

IDTstudios1

Programmer
Aug 8, 2004
72
US
Is there anyway that the following java code can be pulled off by javascript? I know the two languages are very different so i'm asking before I dive into trying to figure it out myself. This will be for a firefox extension so that may clear up a few questions.

Code:
File f = new File("somefile.txt");
FileInputStream fis = new FileInputStream(f);
byte[] data = new byte[(int)f.length()];
fis.read(data);
fis.close();

String u = "[URL unfurl="true"]http://sync.foxysync.com/test.php?action=process&id=1";[/URL]
URL url = new URL(u);
HttpURLConnection huc = (HttpURLConnection)url.openConnection();
huc.setRequestMethod("POST");
huc.setDoOutput(true);
huc.setUseCaches(false);
huc.setFollowRedirects(true);

DataOutputStream dos = new DataOutputStream(huc.getOutputStream());
dos.write(data, 0, data.length);
dos.flush();
dos.close();

huc.disconnect();

thanks
 
I think it could be done with the XMLHttp object however I don't know if it would be compatible with mozilla products...
 
>>File f = new File("somefile.txt");

javascript CANNOT read files locally. this would cause security issues.
however u could use MSXML.HTTP to request an URL in javascript(for IE, do a search for firefox to get the request method for firefox)...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top