I get an empty string returned. it looks like the informaton isn't being passed as a page that can be read in this way.

Is there another way I can get a hold of this information that anyone can think of without asking for the api to be re-written? It would be nice to be able to post an http request using js with this api without resorting to writting php code.

but I need to pass this as part of my Javascript, so as far as I can see I need to encapsulate into an Applescript curl command:

No, that is not a requirement.

The other approach is to use the Socket object and execute the raw HTTP query using the Socket TCP interface. The Javascript tools guide gives an example of an HTTP GET. You might find it easier, but you might not. YMMV.

It seems clear you have not opened Terminal and tested the curl line you have constructed, that would have been an excellent first debugging step. It should be quite clear what the problem is. Ampersands are special characters to the shell and must be quoted when passed to the shell. Unfortunately you quoting may be eaten by AppleScript, so you may need to use not only \& but perhaps \\& or \\\&. Try testing it with do shell script "echo http://testing?foo\&bar" and see what you get.

The other approach is to use the Socket object and execute the raw HTTP query using the Socket TCP interface. The Javascript tools guide gives an example of an HTTP GET. You might find it easier, but you might not. YMMV.

Addendum: It is certainly more portable, as shelling out to curl via Applescript won't work under WIndows (for more than one reason). It might also be faster. Certainly fewer fork()s.

Thanks for the replies. I did try the curl in a terminal window yesterday, but didn't get the result I was wanting. I have tried escaping with one, two and three back slashes, but the terminal result seems to stit out 3 lines of results that are split by the "&" sign.

I did try the curl in a terminal window yesterday, but didn't get the result I was wanting. I have tried escaping with one, two and three back slashes, but the terminal result seems to stit out 3 lines of results that are split by the "&" sign.

The output you supplied is consistent with not quoting the &, but you said that you tried it.

Show us what you did.

However, there is a larger concern:

I am working with an api accepts a url containing a server address, a user id, a user password and returns a status.

I have been sorely remiss in my answer -- user input is involved here? Then you have to worry about quoting the user input! What if the user input contains pass`rm -rf /`word? Then your hard drive will be deleted (well, ok, only files you have write permission on) if this executes, unless you quote the backticks. and there are scores of shell metacharacters to worry about. Passing user input to the shell is a very ba didea,i it's quite easy to generate security concerns. (Though you'll have some with the Socket object too, I guess, but not as severe).

This gets worse with two level of quoting (applescript).

I typically use this function, not designed for security, to address some quoting issues from Javascript to Applescript via shell:

It turns out that I using curl, through 2 layers on Do Script withe the specific API I need to use will not work.

After a lot of trial and error, I resorted to calling on the help of my 15yr old son, who came up with I need to do. What I have needed to do is pass a string containing all the variables needed seaparated by a delimter, to a PHP script that cat re-construct the URL with success.

This works perfectly, but still needs a doscript sequence (JS > AS > SHELL) to pas the url containing the variables.

conn.write(" GET /getassetstatus.php?enc=10.1.1.234~38~11~13446~PASSWORD");

reply = conn.read(999999);

conn.close;

where the php file on my computer "getassetstatus.php" takes the string, and returns a number. This works when being passed as a curl commend 2 layers deep inside doScript, but I want to take out the Applescript dependancy.

I dont know what the "GET" does, and the code I used as a base had "HTTP/1.0\n\n" at the end of the url.