2
I’m having a problem and I can’t fix it, I have a PHP script that submits a form using Curl.
Initially I used the format array(key => value)
to submit the POST data.
However I came up with a problem:
When @ is at the beginning of the field value, Curl considers that I am uploading a file.
To fix this problem I changed the format that mounts the POST to a string with GET format param=@valor
.
However when the value has # (anywhere) it functions as a delimiter (equal in links)
In that case the lor
will be lost.
param=va#lor
Well, I could fix it by making a if/else
and when the value # I would use the format array
, but if by chance the value is @ala#1010
he will fail in both cases.
Can anyone see a light for that problem? Note: Who receives the POST is an external server, so I can not send with Urlencode, because there will not be treated.
Code sample that performs Curl:
function exec_curl($ch, $url, $username, $post = null) {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/cookies/{$username}.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__). "/cookies/{$username}.txt");
return curl_exec($ch);
}
Can’t "skipar" with ?
– Guerra
You need to correctly crunch the value. If it was a
<form>
common being posted, the browser would already do it automatically.– bfavaretto
No @Guerra, if there is a solution I believe it will be by format
array(key => value)
, where I can use @ as first char and it does not consider that it is an upload. Maybe a way to disable this in Curl.– Luis Henrique
@bfavaretto Ai who is, looking at the form’s Ubmit using Chrome’s developer console, the data goes without any of the same. Like I said, by the shape
array
works perfectly, as long as it doesn’t start with @, which is when Curl considers that I’m uploading a file.– Luis Henrique
I believe that the solution would be to shrink, I would have to debug to see if the server accepts some kind of encounter. If you don’t accept I don’t believe it’s possible.
– Guerra
Luis, the Chrome console is tricking you, it does Code before showing.
– bfavaretto
@bfavaretto As a matter of fact, I took the encoded string and played static in PHP and it worked. But I didn’t understand why it didn’t work with the urlencode (I had tested it), I’ll see if it changed something else.
– Luis Henrique