请选择 进入手机版 | 继续访问电脑版
开启辅助访问
QQ登录|微信登录|登录 |立即注册

盖茨网区块链技术社区

API referemce(JSON-RPC)转

转自https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#Qt.2FC.2B.2B

JSON-RPC
Running Bitcoin with the -server argument (or running bitcoind) tells it to function as a HTTP JSON-RPC server, but Basic access authentication must be used when communicating with it, and, for security, by default, the server only accepts connections from other processes on the same machine. If your HTTP or JSON library requires you to specify which 'realm' is authenticated, use 'jsonrpc'.

Bitcoin supports SSL (https) JSON-RPC connections beginning with version 0.3.14. See the rpcssl wiki page for setup instructions and a list of all bitcoin.conf configuration options.

Allowing arbitrary machines to access the JSON-RPC port (using the rpcallowip configuration option) is dangerous and strongly discouraged-- access should be strictly limited to trusted machines.

To access the server you should find a suitable library for your language.

Proper money handling
See the proper money handling page for notes on avoiding rounding errors when handling bitcoin values.

Languages
Python
python-jsonrpc is the official JSON-RPC implementation for Python. It automatically generates Python methods for RPC calls. However, due to its design for supporting old versions of Python, it is also rather inefficient. jgarzik has forked it as Python-BitcoinRPC and optimized it for current versions. Generally, this version is recommended.

While BitcoinRPC lacks a few obscure features from jsonrpc, software using only the ServiceProxy class can be written the same to work with either version the user might choose to install:

from jsonrpc import ServiceProxy
  1. <div>access = ServiceProxy("http://user:password@127.0.0.1:8332")</div><div>access.getinfo()</div><div>access.listreceivedbyaddress(6)</div><div>#access.sendtoaddress("11yEmxiMso2RsFVfBcCa616npBvGgxiBX", 10)</div>
复制代码


The latest version of python-bitcoinrpc has a new syntax.
  1. <div>from bitcoinrpc.authproxy import AuthServiceProxy</div>
复制代码


Ruby
  1. <div>require 'net/http'</div><div>require 'uri'</div><div>require 'json'</div><div> </div><div>class BitcoinRPC</div><div>  def initialize(service_url)</div><div>    @uri = URI.parse(service_url)</div><div>  end</div><div> </div><div>  def method_missing(name, *args)</div><div>    post_body = { 'method' => name, 'params' => args, 'id' => 'jsonrpc' }.to_json</div><div>    resp = JSON.parse( http_post_request(post_body) )</div><div>    raise JSONRPCError, resp['error'] if resp['error']</div><div>    resp['result']</div><div>  end</div><div> </div><div>  def http_post_request(post_body)</div><div>    http    = Net::HTTP.new(@uri.host, @uri.port)</div><div>    request = Net::HTTP::Post.new(@uri.request_uri)</div><div>    request.basic_auth @uri.user, @uri.password</div><div>    request.content_type = 'application/json'</div><div>    request.body = post_body</div><div>    http.request(request).body</div><div>  end</div><div> </div><div>  class JSONRPCError < RuntimeError; end</div><div>end</div><div> </div><div>if $0 == __FILE__</div><div>  h = BitcoinRPC.new('http://user:password@127.0.0.1:8332')</div><div>  p h.getbalance</div><div>  p h.getinfo</div><div>  p h.getnewaddress</div><div>  p h.dumpprivkey( h.getnewaddress )</div><div>  # also see: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list</div><div>end</div>
复制代码


Erlang
Get the rebar dependency from https://github.com/edescourtis/ebitcoind . By default the client will use the configuration in $HOME/.bitcoin/bitcoin.conf or you can instead specify a URI like this:

  1. ebitcoind:start_link(<<"http://user:password@localhost:8332/">>).
复制代码


Here is a usage example:

  1. <div>1> {ok,Pid} = ebitcoind:start_link().</div><div>{ok,<0.177.0>}</div><div>2> ebitcoind:getbalance(Pid).</div><div>8437.02478294</div><div>3> ebitcoind:getinfo(Pid).</div><div>{ok, #{<<"balance">> => 8437.02478294,</div><div>  <<"blocks">> => 260404,</div><div>  <<"connections">> => 8,</div><div>  <<"difficulty">> => 148819199.80509263,</div><div>  <<"errors">> => <<>>,</div><div>  <<"keypoololdest">> => 1420307921,</div><div>  <<"keypoolsize">> => 102,</div><div>  <<"paytxfee">> => 0.0,</div><div>  <<"protocolversion">> => 70002,</div><div>  <<"proxy">> => <<>>,</div><div>  <<"relayfee">> => 1.0e-5,</div><div>  <<"testnet">> => false,</div><div>  <<"timeoffset">> => -3,</div><div>  <<"version">> => 90300,</div><div>  <<"walletversion">> => 60000}}</div><div>4> ebitcoind:setgenerate(Pid,true).</div><div>{ok, null}</div><div>5> ebitcoind:getblocktemplate(Pid, #{}).                     </div><div>{ok,#{<<"bits">> => <<"181b0dca">>,</div><div>      <<"coinbaseaux">> => #{<<"flags">> => <<"062f503253482f">>},</div><div>      <<"coinbasevalue">> => 2518690558,</div><div>      <<"curtime">> => 1420421249,</div><div>      <<"height">> => 337533,</div><div>      <<"mintime">> => 1420416332,</div><div>      <<"mutable">> => [<<"time">>,<<"transactions">>,<<"prevblock">>],</div><div>      <<"noncerange">> => <<"00000000ffffffff">>,</div><div>      <<"previousblockhash">> => <<"000000000000000017ce0a0d328bf84cc597785844393e899e9a971a81679a5f">>,</div><div>      <<"sigoplimit">> => 20000,</div><div>      <<"sizelimit">> => 1000000,</div><div>      <<"target">> => <<"00000000000000001b0dca00000000000000000000000000000000000000"...>>,</div><div>      <<"transactions">> => [#{<<"data">> => <<"01000000049b47ce225d29bff7c18b7df7d7df4693523a52"...>>,</div><div>         <<"depends">> => [],</div><div>         <<"fee">> => 0,</div><div>         <<"hash">> => <<"6d0d76e1f27b3a6f7325923710dcdb4107c9"...>>,</div><div>         <<"sigops">> => 1},</div><div>      ...</div>
复制代码


PHP
The JSON-RPC PHP library also makes it very easy to connect to Bitcoin. For example:

  1. <div>  require_once 'jsonRPCClient.php';</div><div> </div><div>  $bitcoin = new jsonRPCClient('http://user:password@127.0.0.1:8332/');</div><div> </div><div>  echo "<pre>\n";</div><div>  print_r($bitcoin->getinfo()); echo "\n";</div><div>  echo "Received: ".$bitcoin->getreceivedbylabel("Your Address")."\n";</div><div>  echo "</pre>";</div><div></div>
复制代码
Note: The jsonRPCClient library uses fopen() and will throw an exception saying "Unable to connect" if it receives a 404 or 500 error from bitcoind. This prevents you from being able to see error messages generated by bitcoind (as they are sent with status 404 or 500). The EasyBitcoin-PHP library is similar in function to JSON-RPC PHP but does not have this issue.

Java
  1. <div>The easiest way to tell Java to use HTTP Basic authentication is to set a default Authenticator:</div><div>
  2. </div><div>  final String rpcuser ="...";</div><div>  final String rpcpassword ="...";</div><div> </div><div>  Authenticator.setDefault(new Authenticator() {</div><div>      protected PasswordAuthentication getPasswordAuthentication() {</div><div>          return new PasswordAuthentication (rpcuser, rpcpassword.toCharArray());</div><div>      }</div><div>  });</div>
复制代码


Once that is done, any JSON-RPC library for Java (or ordinary URL POSTs) may be used to communicate with the Bitcoin server.

Instead of writing your own implementation, consider using one of the existing wrappers like BitcoindClient4J, btcd-cli4j or Bitcoin-JSON-RPC-Client instead.

Perl
The JSON::RPC package from CPAN can be used to communicate with Bitcoin. You must set the client's credentials; for example:
  1. <div>
  2. </div><div>  use JSON::RPC::Client;</div><div>  use Data::Dumper;</div><div> </div><div>  my $client = new JSON::RPC::Client;</div><div> </div><div>  $client->ua->credentials(</div><div>     'localhost:8332', 'jsonrpc', 'user' => 'password'  # REPLACE WITH YOUR bitcoin.conf rpcuser/rpcpassword</div><div>      );</div><div> </div><div>  my $uri = 'http://localhost:8332/';</div><div>  my $obj = {</div><div>      method  => 'getinfo',</div><div>      params  => [],</div><div>   };</div><div> </div><div>  my $res = $client->call( $uri, $obj );</div><div> </div><div>  if ($res){</div><div>      if ($res->is_error) { print "Error : ", $res->error_message; }</div><div>      else { print Dumper($res->result); }</div><div>  } else {</div><div>      print $client->status_line;</div><div>  }</div>
复制代码



Go
The btcrpcclient package can be used to communicate with Bitcoin. You must provide credentials to match the client you are communicating with.
  1. <div>
  2. </div><div>package main</div><div> </div><div>import (</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"github.com/btcsuite/btcd/chaincfg"</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"github.com/btcsuite/btcrpcclient"</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"github.com/btcsuite/btcutil"</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"log"</div><div>)</div><div> </div><div>func main() {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// create new client instance</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>client, err := btcrpcclient.New(&btcrpcclient.ConnConfig{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>HTTPPostMode: true,</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>DisableTLS:   true,</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>Host:         "127.0.0.1:8332",</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>User:         "rpcUsername",</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>Pass:         "rpcPassword",</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}, nil)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if err != nil {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>log.Fatalf("error creating new btc client: %v", err)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// list accounts</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>accounts, err := client.ListAccounts()</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if err != nil {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>log.Fatalf("error listing accounts: %v", err)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// iterate over accounts (map[string]btcutil.Amount) and write to stdout</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>for label, amount := range accounts {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>log.Printf("%s: %s", label, amount)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// prepare a sendMany transaction</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>receiver1, err := btcutil.DecodeAddress("1someAddressThatIsActuallyReal", &chaincfg.MainNetParams)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if err != nil {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>log.Fatalf("address receiver1 seems to be invalid: %v", err)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>receiver2, err := btcutil.DecodeAddress("1anotherAddressThatsPrettyReal", &chaincfg.MainNetParams)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if err != nil {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>log.Fatalf("address receiver2 seems to be invalid: %v", err)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>receivers := map[btcutil.Address]btcutil.Amount{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>receiver1: 42,  // 42 satoshi</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>receiver2: 100, // 100 satoshi</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// create and send the sendMany tx</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>txSha, err := client.SendMany("some-account-label-from-which-to-send", receivers)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if err != nil {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>log.Fatalf("error sendMany: %v", err)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>log.Printf("sendMany completed! tx sha is: %s", txSha.String())</div><div>}</div>
复制代码


.NET (C#)
The communication with the RPC service can be achieved using the standard http request/response objects. A library for serializing and deserializing Json will make your life a lot easier:

Json.NET ( http://james.newtonking.com/json ) is a high performance JSON package for .NET. It is also available via NuGet from the package manager console ( Install-Package Newtonsoft.Json ).

The following example uses Json.NET:
  1. <div>HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost.:8332");</div><div> webRequest.Credentials = new NetworkCredential("user", "pwd");</div><div> /// important, otherwise the service can't desirialse your request properly</div><div> webRequest.ContentType = "application/json-rpc";webRequest.Method = "POST";</div><div> </div><div> JObject joe = new JObject();</div><div> joe.Add(new JProperty("jsonrpc", "1.0"));</div><div> joe.Add(new JProperty("id", "1"));</div><div> joe.Add(new JProperty("method", Method));</div><div> // params is a collection values which the method requires..</div><div> if (Params.Keys.Count == 0)</div><div> {</div><div>  joe.Add(new JProperty("params", new JArray()));</div><div> }</div><div> else</div><div> {</div><div>     JArray props = new JArray();</div><div>     // add the props in the reverse order!</div><div>     for (int i = Params.Keys.Count - 1; i >= 0; i--)</div><div>     {</div><div>        .... // add the params</div><div>     }</div><div>     joe.Add(new JProperty("params", props));</div><div>     }</div><div> </div><div>     // serialize json for the request</div><div>     string s = JsonConvert.SerializeObject(joe);</div><div>     byte[] byteArray = Encoding.UTF8.GetBytes(s);</div><div>     webRequest.ContentLength = byteArray.Length;</div><div>     Stream dataStream = webRequest.GetRequestStream();</div><div>     dataStream.Write(byteArray, 0, byteArray.Length);</div><div>     dataStream.Close();</div><div> </div><div> </div><div>     WebResponse webResponse = webRequest.GetResponse();</div><div> </div><div>     ... // deserialze the response</div>
复制代码

There is also a wrapper for Json.NET called Bitnet (https://sourceforge.net/projects/bitnet) implementing Bitcoin API in more convenient way:

  1. <div>     BitnetClient bc = new BitnetClient("http://127.0.0.1:8332");</div><div>     bc.Credentials = new NetworkCredential("user", "pass");</div><div> </div><div>     var p = bc.GetDifficulty();</div><div>     Console.WriteLine("Difficulty:" + p.ToString());</div><div> </div><div>     var inf = bc.GetInfo();</div><div>     Console.WriteLine("Balance:" + inf["balance"]);</div>
复制代码


A more complete library and wrapper for Bitcoin (also for Litecoin and all Bitcoin clones) is BitcoinLib (https://github.com/GeorgeKimionis/BitcoinLib) which is also available via NuGet from the package manager console (Install-Package BitcoinLib).

Querying the daemon with BitcoinLib is as simple as:

  1. <div>     IBitcoinService bitcoinService = new BitcoinService();</div><div> </div><div>     var networkDifficulty = bitcoinService.GetDifficulty();</div><div>     var myBalance = bitcoinService.GetBalance();</div>
复制代码



Node.js
node-bitcoin (npm: bitcoin)
Example using node-bitcoin:
  1. <div>
  2. </div><div>var bitcoin = require('bitcoin');</div><div>var client = new bitcoin.Client({</div><div>  host: 'localhost',</div><div>  port: 8332,</div><div>  user: 'user',</div><div>  pass: 'pass'</div><div>});</div><div> </div><div>client.getDifficulty(function(err, difficulty) {</div><div>  if (err) {</div><div>    return console.error(err);</div><div>  }</div><div> </div><div>  console.log('Difficulty: ' + difficulty);</div><div>});</div>
复制代码


Example using Kapitalize:
  1. <div>var client = require('kapitalize')()</div><div> </div><div>client.auth('user', 'password')</div><div> </div><div>client</div><div>.getInfo()</div><div>.getDifficulty(function(err, difficulty) {</div><div>  console.log('Dificulty: ', difficulty)</div><div>})</div>
复制代码


Command line (cURL)
You can also send commands and see results using cURL or some other command-line HTTP-fetching utility; for example:

  1. <div>  curl --user user --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }' </div><div>    -H 'content-type: text/plain;' http://127.0.0.1:8332/</div>
复制代码


You will be prompted for your rpcpassword, and then will see something like:
  1. <div>
  2. </div><div>  {"result":{"balance":0.000000000000000,"blocks":59952,"connections":48,"proxy":"","generate":false,</div><div>     "genproclimit":-1,"difficulty":16.61907875185736},"error":null,"id":"curltest"}</div><div>Clojure</div><div>clj-btc is a Clojure wrapper for the bitcoin API.</div><div>
  3. </div><div>user=> (require '[clj-btc.core :as btc])</div><div>nil</div><div>user=> (btc/getinfo)</div><div>{"timeoffset" 0, "protocolversion" 70001, "blocks" 111908, "errors" "",</div><div> "testnet" true, "proxy" "", "connections" 4, "version" 80500,</div><div> "keypoololdest" 1380388750, "paytxfee" 0E-8M,</div><div> "difficulty" 4642.44443532M, "keypoolsize" 101, "balance" 0E-8M,</div><div> "walletversion" 60000}</div><div>C</div><div>The C API for processing JSON is Jansson. C applications like libblkmaker use cURL for making the calls and Jansson for interpreting the JSON that cURL fetches.</div><div>
  4. </div><div>For example basic usage (which can be easily modified for Bitcoin RPC), see the Jansson example github_commits.c and the associated tutorial.</div><div>
  5. </div><div>The following does with libcurl what the cURL example above does:</div><div>#include <stdlib.h></div><div> </div><div>#include <curl/curl.h></div><div> </div><div>int main()</div><div>{</div><div>    CURL *curl = curl_easy_init();</div><div>    struct curl_slist *headers = NULL;</div><div> </div><div>    if (curl) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>const char *data =</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>    "{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }";</div><div> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>headers = curl_slist_append(headers, "content-type: text/plain;");</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);</div><div> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:8332/");</div><div> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) strlen(data));</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);</div><div> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>curl_easy_setopt(curl, CURLOPT_USERPWD,</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span> "bitcoinrpcUSERNAME:bitcoinrpcPASSWORD");</div><div> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);</div><div> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>curl_easy_perform(curl);</div><div>    }</div><div>    return 0;</div><div>}</div>
复制代码


This output can be parsed with Jansson, à la the Jansson tutorial linked to above.
(source: Bitcoin StackExchange)

Qt/C++
QJsonRpc is a Qt/C++ implementation of the JSON-RPC protocol. It integrates nicely with Qt, leveraging Qt's meta object system in order to provide services over the JSON-RPC protocol. QJsonRpc is licensed under the LGPLv2.1.

  1. <div>/*</div><div> * Copyright (C) 2012-2013 Matt Broadstone</div><div> * Contact: http://bitbucket.org/devonit/qjsonrpc</div><div> *</div><div> * This file is part of the QJsonRpc Library.</div><div> *</div><div> * This library is free software; you can redistribute it and/or</div><div> * modify it under the terms of the GNU Lesser General Public</div><div> * License as published by the Free Software Foundation; either</div><div> * version 2.1 of the License, or (at your option) any later version.</div><div> *</div><div> * This library is distributed in the hope that it will be useful,</div><div> * but WITHOUT ANY WARRANTY; without even the implied warranty of</div><div> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</div><div> * Lesser General Public License for more details.</div><div> */</div><div>#include <QCoreApplication></div><div>#include <QAuthenticator></div><div>#include <QStringList></div><div>#include <QDebug></div><div> </div><div>#include "qjsonrpchttpclient.h"</div><div> </div><div>class HttpClient : public QJsonRpcHttpClient</div><div>{</div><div>    Q_OBJECT</div><div>public:</div><div>    HttpClient(const QString &endpoint, QObject *parent = 0)</div><div>        : QJsonRpcHttpClient(endpoint, parent)</div><div>    {</div><div>        // defaults added for my local test server</div><div>        m_username = "bitcoinrpc";</div><div>        m_password = "232fb3276bbb7437d265298ea48bdc46";</div><div>    }</div><div> </div><div>    void setUsername(const QString &username) {</div><div>        m_username = username;</div><div>    }</div><div> </div><div>    void setPassword(const QString &password) {</div><div>        m_password = password;</div><div>    }</div><div> </div><div>private Q_SLOTS:</div><div>    virtual void handleAuthenticationRequired(QNetworkReply *reply, QAuthenticator * authenticator)</div><div>    {</div><div>        Q_UNUSED(reply)</div><div>        authenticator->setUser(m_username);</div><div>        authenticator->setPassword(m_password);</div><div>    }</div><div> </div><div>private:</div><div>    QString m_username;</div><div>    QString m_password;</div><div> </div><div>};</div><div> </div><div>int main(int argc, char **argv)</div><div>{</div><div>    QCoreApplication app(argc, argv);</div><div>    if (app.arguments().size() < 2) {</div><div>        qDebug() << "usage: " << argv[0] << "[-u username] [-p password] <command> <arguments>";</div><div>        return -1;</div><div>    }</div><div> </div><div>    HttpClient client("http://127.0.0.1:8332");</div><div>    if (app.arguments().contains("-u")) {</div><div>        int idx = app.arguments().indexOf("-u");</div><div>        app.arguments().removeAt(idx);</div><div>        if(idx<app.arguments().count())</div><div>              client.setUsername(app.arguments().takeAt(idx));</div><div>        else qDebug()<<"-u value not defined";</div><div>    }</div><div> </div><div>    if (app.arguments().contains("-p")) {</div><div>        int idx = app.arguments().indexOf("-p");</div><div>        app.arguments().removeAt(idx);</div><div>        if(idx<app.arguments().count())</div><div>            client.setPassword(app.arguments().takeAt(idx));</div><div>        else qDebug()<<"-p value not defined";</div><div>    }</div><div> </div><div>    QJsonRpcMessage message = QJsonRpcMessage::createRequest(app.arguments().at(1));</div><div>    QJsonRpcMessage response = client.sendMessageBlocking(message);</div><div>    if (response.type() == QJsonRpcMessage::Error) {</div><div>        qDebug() << response.errorData();</div><div>        return -1;</div><div>    }</div><div> </div><div>    qDebug() << response.toJson();</div><div>}</div>
复制代码


0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则