Formjson PHP for CURL ,

Asked

Viewed 77 times

0

How to go from ...

file_get_contents()

for CURL or Guzzle

$content = http_build_query(array(
'oid' => '00SH1000000ASZF',
'retURL' => 'https://www.site.com.br/', 
'first_name' => $nome,                                              
'last_name' => $sobrenome,
'cpf__c' => rmCaracter($f['cpf']),
'mobile' => rmCaracter($f['phone']),
'email' => $f['email'],                                             
'type__c' => 'HAB',
'Lead_Source' => 'Website Concessionaria',
'sub_source_media__c' => 'Site',                                  
'dealer_code_interest__c' => '137492',
'opt_in_email__c' => '1',
'opt_in_phone__c' => '1',                                               
'model_interest__c' => $f['model'],
));

$context = stream_context_create(array(
'http' => array(
'method'  => 'POST',
'content' => $content,
)
));                                             

$result = file_get_contents('https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8', null, $context);

I’m getting an error in $result .::

Warning: file_get_contents(https://webto.salesforce.com/servlet/servlet.WebToLead...): failed to open stream: HTTP request failed! HTTP/1.1 400 TLS 1.1 or Higher required in /home/Storage/9/8e/3d/teste1124/public_html/tpl/site.php on line 124

I believe I’m the solution because, uh... If I put the url of this webservice in the action of a form and send the same data, I don’t have the error, but the way I mounted my json , yes I have this error there.

My Form + Json = https://pastebin.com/mvai8JP7

Most housings now lock the furl_open parameter which allows using file_get_contents() to load data from a URL external. I think I can use CURL or a PHP client library as Guzzle, as solution.

  • Edith your question and clarify your problem, because the way you are not to understand.

  • @Wéllingthon M. de Souza I need to change my JSON to CURL because ... I believe to be the Solution because, ... If I put the url of this webservice in the action of a form and send the same data, I do not have the error, but the way I mounted my json , yes I have this error there.

  • @Articuno Can help you know........ I’m not getting through !

1 answer

0

Using Curl would look like this:

$content = array(
  'oid' => '00SH1000000ASZF',
  'retURL' => 'https://www.site.com.br/',
  'first_name' => $nome,
  'last_name' => $sobrenome,
  'cpf__c' => rmCaracter($f['cpf']),
  'mobile' => rmCaracter($f['phone']),
  'email' => $f['email'],
  'type__c' => 'HAB',
  'Lead_Source' => 'Website Concessionaria',
  'sub_source_media__c' => 'Site',
  'dealer_code_interest__c' => '137492',
  'opt_in_email__c' => '1',
  'opt_in_phone__c' => '1',
  'model_interest__c' => $f['model'],
);

$context = http_build_query($content);
$url = 'https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';

// Abre a conexão
$ch = curl_init();

// Seta a URL, método como POST, e os dados a ser enviado
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $context);

// Executa
$result = curl_exec($ch);
echo $result;

// Fecha a conexão
curl_close($ch);

Note: It was not possible to do the test, because at the moment I am not in a suitable computer.

Reference

  • echo $result; came = 1 , signal that it worked ?

  • If this is the return that the site of when it receives the information successfully, yes, because it is returning TRUE, there is no way you can check in the site where you are making the request if it received ?

  • @Wéllingthon M. de Souza Did not enter the leads No !

  • @Paulomaia what has in $nome ? how you are getting the values of these variables?

  • @Wéllingthon M. de Souza Veja = https://pastebin.com/mvai8JP7

  • @Wéllingthon M. de Souza Not receiving no !

  • This link is the same as the one in the question, how were you using the answer code? Can you see the return when you do it by form ? The form is submitted via Ajax ? If yes, go on Developer Tools > Network

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.