0

I am not familer with PHP and need help to convert below php code to command line curl. Please advise. I tried different ways using postman but did not work out.

$username="";
$password="";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://www.xxx.co.uk/apinew");
curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('username' => $username,'pass' => $password,'type' => 'both','buildname' => 'Little Westwood House','subBname' => '','number' => '','depstreet' => '','street' => 'Bucks Hill','postcode' => 'WD4 9AR')));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

print_r($server_output);
yivi
  • 42,438
  • 18
  • 116
  • 138
Moblize IT
  • 1,140
  • 2
  • 18
  • 44
  • You don't need to build query, just put an array as param would work. `curl_setopt($ch, CURLOPT_POSTFIELDS, array('username' => $username,'pass' => $password,'type' => 'both','buildname' => 'Little Westwood House','subBname' => '','number' => '','depstreet' => '','street' => 'Bucks Hill','postcode' => 'WD4 9AR');` – Pascal Tovohery Feb 27 '19 at 07:32
  • well i need the command line curl from above code. plz advise – Moblize IT Feb 27 '19 at 07:39
  • Does this answer your question? [How to convert Php CURL request to command line curl](https://stackoverflow.com/questions/42671535/how-to-convert-php-curl-request-to-command-line-curl) – Potherca May 31 '22 at 10:31
  • @Potherca It definitely doesn't answer the question. That lack of answer led me straight here. I believe I will have to create such a utility, because it doesn't seem to exist ANYWHERE. – Theodore R. Smith Jul 01 '22 at 01:26
  • @TheodoreR.Smith I am stuck in a similar situation. The question I linked works for some people but, indeed, not for the scenario I am currently in. About creating such a utility, I've gotten as far as parsing PHP code to retrieve all the cURL options. I still need to convert them to a CLI curl call. Maybe my effort can serve as help or inspiration. See https://gist.github.com/Potherca/f405d876435eca73ded41ebbfa1d1c6d – Potherca Jul 01 '22 at 13:43

0 Answers0