N
N
Novomir Lobanov2015-03-26 09:13:43
PHP
Novomir Lobanov, 2015-03-26 09:13:43

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

3 answer(s)
D
Dmitry Entelis, 2015-03-26
@DmitriyEntelis

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);

M
Mikhail Goryachkin, 2015-03-26
@abaddon65

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
  });
};

M
Mike, 2015-03-26
@Mike77

stefangabos.ro/php-libraries/zebra-curl

$curl->post(array(
    'http://www.somewebsite.com'  =>  array(
        'data_1'  =>  'value 1',
        'data_2'  =>  'value 2',
        'data_3'  =>  '@absolute/path/to/file.ext',
), 'mycallback');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question