Search
 
SCRIPT & CODE EXAMPLE
 

PHP

curl post json

curl -X POST -H "Content-Type: application/json" 
 -d '{"username":"abc","password":"abc"}' 
 https://api.example.com/v2/login
Comment

php curl post json

$ch = curl_init( $url );
# Setup request to send json via POST.
$payload = json_encode( array( "customer"=> $data ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
Comment

php post curl json

function postCurl(array $postFields, string $url)
{
    $post = $postFields;
    if (count($post) == 0) {
        return false;
    }
    $url = trim($url);
    $postdata = json_encode($post, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    $result = curl_exec($ch);
    $decodedResult = json_decode($result, JSON_UNESCAPED_UNICODE);
    if ($decodedResult['status'] == 'ok') {
        return $decodedResult;
    } else {
        return false;
    }
    curl_close($ch);
}
Comment

php curl post

// set post fields
$post = [
    'username' => 'user1',
    'password' => 'passuser1',
    'gender'   => 1,
];

$ch = curl_init('http://www.example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

// execute!
$response = curl_exec($ch);

// close the connection, release resources used
curl_close($ch);

// do anything you want with your response
var_dump($response);
Comment

php curl post json

function curl( string $url, array $data)
{
	function send($url, $request)
	{
		$ch = curl_init();
		$headers = [
			'Accept: application/json',
			'Content-Type: application/json',
		];
		$options = [
			CURLOPT_URL => $url,
			CURLOPT_POST => true,
			CURLOPT_POSTFIELDS => $request,
			CURLOPT_FOLLOWLOCATION => true,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_HEADER => true,
			CURLOPT_HTTPHEADER => $headers,
		];

		curl_setopt_array($ch, $options);
		$response = curl_exec($ch);
		curl_close($ch);
		
		return $response;
	}

	return send($url, json_encode($data));
}
Comment

curl json post

<?php

$url = "https://reqbin.com/echo/post/json";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$headers = array(
   "Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$data = '{"login":"my_login","password":"my_password"}';

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);

?>
Comment

PREVIOUS NEXT
Code Example
Php :: check image is available on server php 
Php :: how to redirect with php 
Php :: install php-8 extentions 
Php :: php find multiple strings in string 
Php :: php array index exists 
Php :: laravel format number blade 
Php :: wordpress get archive title 
Php :: get name of parent dir php 
Php :: print array php 
Php :: npm watch laravel 
Php :: laravel old request hmtl select 
Php :: string to datetime php 
Php :: how to set timezone for iran in laravel 
Php :: laravel doesNotHave in model 
Php :: string to uppercase laravel 
Php :: wp wc php if cart page is empty redirect 
Php :: import class route laravel 
Php :: php mysql date format 
Php :: for loop php 
Php :: php convert array to object 
Php :: php image to base64 
Php :: php search on array 
Php :: laravel foreign key 
Php :: how get all files name in one folder in laravel 
Php :: get_declared_classes 
Php :: Replicating claims as headers is deprecated and will removed from v4.0. Please manually set the header if you need it replicated. 
Php :: laravel controller return message 
Php :: php get all elements of array except last 
Php :: change laravel mix to run on different port 
Php :: laravel get all vendor files 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =