Alex Rivera | Logout

Escaping CURL @ symbol with PHP

Asked 2009-03-15T18:30:34.793
10

I'm writing a php application that submits via curl data to sign up for an iContact email list. However I keep getting an invalid email address error. I think this may be due to the fact that I'm escaping the @ symbol so it looks like %40 instead of @. Also, according to the php documentation for curl_setopt with CURLOPT_POSTFIELDS:

The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path.

So, is there anyway to pass the @ symbol as post data through curl in php without running it through urlencode first?

Edit
Report

1 Answer

4

I ran into the same issue, though with curl itself and not PHP curl.

When using curl's field option '-F' a leading @ symbol will not be sent in the POST but instead will instruct curl to send the file name that immediately succeeds the symbol as part of the POST.

Fortunately, curl offers another option '--form-string', which behaves the same way as '-F', except that the 'form-string' option is not parsed.

As an example, if you want to use curl to POST field1 with value "@value" and file1 with the file "testfile.txt" you can do so as follows:

curl "http://www.url.com" --form-string "field1=@value" -F "file1=@testfile.txt"
answered 2011-12-09T02:48:40.520

Your Answer