addNeighbors

Body参数

  • command 必须

      字符串 addNeighbors
    
  • uris 必须

     字符串数组
    
     URI元素列表
    

    添加邻居节点列表到你的节点。值得注意的是,这个方法是临时的,当重启IRI程序的,通过这个方法添加的邻居节点会被移除。

    节点的URI (统一资源定位符)是:

    udp://IPADDRESS:PORT

例子

当前节点:http://localhost:14265/

cURL

curl http://localhost:14265 \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{"command": "addNeighbors", "uris": ["udp://8.8.8.8:14265", "udp://8.8.8.5:14265"]}'

Python

import urllib2
import json

command = {
  'command': 'addNeighbors',
  'uris': ['udp://8.1.8.8:14265', 'udp://8.8.2.5:14265']
}

stringified = json.dumps(command)

headers = {'content-type': 'application/json'}

request = urllib2.Request(url="http://localhost:14265", data=stringified, headers=headers)
returnData = urllib2.urlopen(request).read()

jsonData = json.loads(returnData)

print jsonData

NodeJS

var request = require('request');

var command = {
  'command': 'addNeighbors',
  'uris': ['udp://8.1.8.8:14265', 'udp://8.8.2.5:14265']
}

var headers = {
    'Content-Type': 'application/json',
    'Content-Length': JSON.stringify(command).length
};

var options = {
  url: 'http://localhost:14265',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': Buffer.byteLength(JSON.stringify(command))
  },
  json: command
};

request(options, function (error, response, data) {
  if (!error && response.statusCode == 200) {
    console.log(data);
  }
});

返回结果

200 OK:

{
  "addedNeighbors": 0, 
  "duration": 2
}

400 Bad Request

{}

results matching ""

    No results matching ""