cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: PHP - CURL - Custom authentication script

From: Michael Gawrychowski <mgawrych_at_excelmicro.com>
Date: Tue, 29 Mar 2011 16:08:14 -0400

Thank you very much! It helped me a lot. I recreated my code a little bit
and now I'm able to submit the data, but their system rejects my request
saying that 3 of the values are not selected:

j_id0%3Aj_id6%3Ainfo%3Aj_id16%3AsecGroup%3Agroup=Tech+Support
j_id0%3Aj_id6%3Ainfo%3Aj_id16%3AsecFunction%3Afunction=a0T60000000IIsbEAG
j_id0%3Aj_id6%3Ainfo%3Aj_id16%3AsecSubFunction%3Asubfunction=a0e60000000JZHLAA4

What it could be? Even if I copy these over from the firefox request in
Firefox it gets me the same. What do you think?

This is how much code look like now:

$posts =
"j_id0%3Aj_id6=j_id0%3Aj_id6&j_id0%3Aj_id6%3Ainfo%3Aj_id16%3AsecAsset%3Aasset=02i60000004ALBt&j_id0%3Aj_id6%3Ainfo%3Aj_id16%3AsecProductLine%3Aor-data=&j_id0%3Aj_id6%3Ainfo%3Aj_id16%3AsecGroup%3Agroup=Tech+Support&j_id0%3Aj_id6%3Ainfo%3Aj_id16%3AsecFunction%3Afunction=a0T60000000IIsbEAG&j_id0%3Aj_id6%3Ainfo%3Aj_id16%3AsecSubFunction%3Asubfunction=a0e60000000JZHLAA4&j_id0%3Aj_id6%3Ainfo%3Aj_id16%3AsecLanguage%3Alanguage=English&j_id0%3Aj_id6%3Ainfo%3Aj_id16%3AsecPriority%3Apriority=P4+-+Low+Impact&j_id0%3Aj_id6%3Adetails%3AApps%3AsecCountry%3Acountry=&j_id0%3Aj_id6%3Adetails%3AApps%3AsecCPINApps%3Acpinapps=&j_id0%3Aj_id6%3Adetails%3ADesc%3AsecSubject%3Asubject=TESTTES&j_id0%3Aj_id6%3Adetails%3ADesc%3AsecDescription%3Adescription=TEST&j_id0%3Aj_id6%3Adetails%3ADesc%3AsecReproduce%3Areproduce=&j_id0%3Aj_id6%3Adetails%3Aj_id59%3Aj_id60=Create+New+Case&com.salesforce.visualforce.ViewState=".urlencode($result[1])."&com.salesforce.visualforce.ViewStateMAC=".urlencode($result1[1])."&com.salesforce.visualforce.ViewStateCSRF=".urlencode($result2[1])."";

curl_setopt($ch, CURLOPT_URL,
"https://c.na4.visual.force.com/apex/NewCase");

curl_setopt($ch, CURLOPT_REFERER,"
https://c.na4.visual.force.com/apex/NewCase");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $posts);
$verbose_file = 'xyz.txt';
$fp = fopen ( $verbose_file, 'w+' );
curl_setopt ( $ch, CURLOPT_VERBOSE, TRUE );
curl_setopt ( $ch, CURLOPT_STDERR, $fp );
fwrite ( $fp, "Post data sent: " . $posts . "\n\n" );
$content4 = curl_exec ($ch);
echo $content4;
print "<pre>\n";
print_r(curl_getinfo($ch)); // get error info
echo "\n\ncURL error number:" .curl_errno($ch); // print error info
echo "\n\ncURL error:" . curl_error($ch);
print "</pre>\n";

THanks a lot!

On Tue, Mar 29, 2011 at 2:00 PM, David Colter <dolan2go_at_yahoo.com> wrote:

> Michael,
>
> > Content-Length: 102999
> > Content-Type: multipart/form-data;
> boundary=----------------------------d98e0ca1859e
> >
> > < HTTP/1.1 500 Internal Server Error
>
> The content length says it: That's a huge string.
>
> The problem is clearly in that $posts string. I see you're building an
> array. I think curl configures the 'Content-Type:
> application/x-www-form-urlencoded' for a string instead of 'Content-Type:
> multipart/form-data' for an array. I can't speak to how to accomplish the
> task with an array. Instead, I create a string after capturing or setting
> the variables needed within. Please look at the bottom the server 'request
> header' from a firefox request and then duplicate that post string. In Live
> Headers, it is directly beneath the Content-Length: and is indented. It'll
> most likely look like:
>
> attribute_1=value_1&attribute_2=value_2&....
>
> You might have to use urlencode ( ) on values of the string, to make curl
> send it like the raw header.
>
> Your problem lies there. It's still a matter of making the curl string be
> formed like the browsers string. If need be, include the browser's post
> string in a reply.
>
> David
>
>
>
>
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2011-03-29