php curl post application 2fx www form urlencoded

Solutions on MaxInterview for php curl post application 2fx www form urlencoded by the best coders in the world

showing results for - "php curl post application 2fx www form urlencoded"
Samuel
17 Feb 2018
1//this send application/x-www-form-urlencoded                                                                                                     
2 function httpPostXform($url, $data) {                                                                 
3    $curl = curl_init($url);                                                                            
4    curl_setopt($curl, CURLOPT_POST, true);                                                             
5    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));                                    
6    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);                                                   
7    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));   
8    $response = curl_exec($curl);                                                                       
9    curl_close($curl);                                                                                  
10    return $response;                                                                      
11}                                                                                                       
12$r = httpPostXform("https://www.somesite.com",array("user_id"=>10,"sex"=>"male"));