一个cURL连接不起作用,但第二个是

时间:2015-03-17 19:56:29

标签: php post curl

我正在尝试建立一个curl连接,将一个帖子提交发送到两个外部数据库,第一个连接获取原始post数组,第二个获取重建的关联数组。奇怪的是,第一个不起作用,但第二个是。

我无法弄清楚如何让这个编辑器让我提交代码。我已经尝试按下菜单中的代码按钮,我尝试在所有行前面放置4个空格,但每次提交时它都会一直抱怨代码。

我可以提供表单,curl函数和post数组的print_r以及curl连接的结果输出。

我知道两个连接的唯一区别实际上是正在使用的本地端口(我觉得很奇怪),而且工作的端口有d / l值,而不能正常工作的那个/ l值为0.

与此同时,我会看看是否可以向您展示所有内容的副本。

    $post_data2['name']=$_POST['first_name'];
$post_data2['custom_LastName1']=$_POST['last_name'];
$post_data2['email']=$_POST['email'];
$post_data2['custom_Phone']=$_POST['phone'];
$post_data2['webform_id'] = 8114201;
$post_data1=$_POST;


//create cURL connection for salesforce db
$ch1 =  curl_init('https://test.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8');
print_r($_POST); 
//set options
//set options
curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch1, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($ch1, CURLOPT_POSTFIELDS, $_POST);

//perform our request
curl_exec($ch1);


$result = curl_exec($ch1);

//show information regarding the request
print_r(curl_getinfo($ch1));
echo 'errors';
echo curl_errno($ch1) . '-' . curl_error($ch1);

//close the connection
curl_close($ch1);



//curl connection for getresponse db
$ch2 = curl_init('https://app.getresponse.com/add_contact_webform.html?u=8QGL');

//set options
curl_setopt($ch2, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch2, CURLOPT_USERAGENT,
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($ch2, CURLOPT_POSTFIELDS, $post_data2);

//perform our request
curl_exec($ch2);
$result = curl_exec($ch1);

//show information regarding the request
print_r(curl_getinfo($ch2));
echo curl_errno($ch2) . '-' .curl_error($ch2);


curl_close($ch2);

 output  including a print_r($_POST).  The first curl output is the broken one, the second is the working one.
 Array ( [oid] => 00DF00000007QKR [first_name] => Jennifer [last_name] => Cowles [email] => tyjencowles@gmail.com [phone] => 9286711697 [company] => NWU [Campaign_ID] => 701F0000000mimp [submit] => Yes, call me now! ) Array ( [url] => https://test.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8 [content_type] => text/html;charset=UTF-8 [http_code] => 200 [header_size] => 339 [request_size] => 292 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.097856 [namelookup_time] => 2.3E-5 [connect_time] => 2.7E-5 [pretransfer_time] => 9.9E-5 [size_upload] => 909 [size_download] => 0 [speed_download] => 0 [speed_upload] => 9289 [download_content_length] => -1 [upload_content_length] => 909 [starttransfer_time] => 0.020784 [redirect_time] => 0 [certinfo] => Array ( ) [primary_ip] => 204.14.234.45 [primary_port] => 443 [local_ip] => 10.0.2.142 [local_port] => 48534 [redirect_url] => ) errors0-Array ( [url] => https://app.getresponse.com/add_contact_webform.html?u=8QGL [content_type] => text/html; charset=utf-8 [http_code] => 200 [header_size] => 815 [request_size] => 283 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.692412 [namelookup_time] => 0.009802 [connect_time] => 0.102256 [pretransfer_time] => 0.298121 [size_upload] => 590 [size_download] => 19354 [speed_download] => 27951 [speed_upload] => 852 [download_content_length] => -1 [upload_content_length] => 590 [starttransfer_time] => 0.391054 [redirect_time] => 0 [certinfo] => Array ( ) [primary_ip] => 207.8.198.26 [primary_port] => 443 [local_ip] => 10.0.2.142 [local_port] => 37214 [redirect_url] => ) 0-

由于 詹妮弗考尔斯

1 个答案:

答案 0 :(得分:0)

事实证明,salesforce需要封装$ _POST。

这一行: curl_setopt($ ch1,CURLOPT_POSTFIELDS,$ _POST; 改为: curl_setopt($ ch1,CURLOPT_POSTFIELDS,http_build_query($ _ POST))

现在宇宙中的一切都很好!