Shortening cURL?

Would this be an efficient way of using cURL?

script curl
	on retrieve(x)
		return (do shell script "curl -s -S " & x) as string
	end retrieve
	on retrievepro(x, i)
		return (do shell script "curl -s -S " & i & space & quoted form of x) as string
	end retrievepro
	on post(x, i)
		return (do shell script "curl -s -S -d \"" & i & "\" " & quoted form of x) as string
	end post
end script
curl's retrieve("http://www.google.com/")

Hi,

I would add some error handling


on retrieve(x)
	try
		return (do shell script "curl -s -S " & quoted form of x)
	on error e
		return e
	end try
end retrieve

There is a problem… if there was an error, and I wanted to receive the HTML of a page, I just get the label of the error. I would rather have

try
	curl's retrieve(x)
on error e
	display dialog e
end try

Hello
I guess you want to get the output And want to check if there was an error of the curl command.

I have understood it that curl returns 0 when there is no error as every sane shell command, except true. :slight_smile:

I propose that you collect the output of the curl command and “echo $?” in a subshell to gather all the output in result:


	set theResult to do shell script "(" & yourCurlCommand & " ; echo $? )"
	set errorcode to last paragraph of theResult as number
	if errorcode is not 0 then 
	 ..
	end if

Hopes this helps and Best Regards

McUsr