Answer the question
In order to leave comments, you need to log in
How to send a PUT request to the correct address (php, json)?
There is a service, you need to send a PUT request to it with an order by reference.
I figured out how to form the json array, but with sending the problem.
Can you tell me how to do this or where to see a working example?
Answer the question
In order to leave comments, you need to log in
bit.ly/1CcEcUH first link
$data = array('username'=>'dog','password'=>'tall');
$data_json = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
Well, in js, you can use jQuery and write a small f-th:
$.put = function(url, data, callback, type){
if ( $.isFunction(data) ){
type = type || callback,
callback = data,
data = {}
}
return $.ajax({
url: url,
type: 'PUT',
success: callback,
data: data,
contentType: type
});
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question