我正在使用來自dzhuvinov的JSON-RPC 2.0的Java庫。我在爲呼叫設置我的用戶名和密碼爲basic access authenticaition時遇到問題。我的代碼如下所示:JSON RPC Java dzhuvinov - 如何設置用戶名和密碼?
public static void main(String[] args)
{
URL serverURL = null;
try {
serverURL = new URL("http://user:[email protected]:18332/");
} catch (MalformedURLException e) {
System.err.println(e.getMessage());
return;
}
JSONRPC2Session mySession = new JSONRPC2Session(serverURL);
String method = "getinfo";
int requestID = 0;
JSONRPC2Request request = new JSONRPC2Request(method, requestID);
JSONRPC2Response response = null;
try {
response = mySession.send(request);
} catch (JSONRPC2SessionException e) {
System.err.println(e.getMessage());
return;
}
if (response.indicatesSuccess())
System.out.println(response.getResult());
else
System.out.println(response.getError().getMessage());
}
而且我得到的迴應:
Network exception: Server returned HTTP response code: 401 for URL: http://user:[email protected]:18332/
嘗試在Python類似的代碼,我得到正確的結果:
access = jsonrpc.ServiceProxy("http://user:[email protected]:18332/")
print access.getinfo()
我如何配置我的JSON RPC調用的基本訪問身份驗證?