2011-07-06 128 views
2

与rpc服务通信好吧即时通信阻止下面的代码给了我一个HTTP 400错误,告诉我有提交的数据有问题,但我无法弄清楚什么!:(使用indy HTTP客户端和superobject DELPHI http 400错误代码

客户端设置为编码URL(IVE尝试都真/假);

procedure TForm2.Button1Click(Sender: TObject); 

    var 
    O:Isuperobject; 
    T:Tstringlist; 
    begin 
     T := Tstringlist.Create; 
     O := SO('{"jsonrpc": "1.0", "method": getinfo, "params": "[]" }'); 
     t.Add(o.AsString) ; 
     idhttp1.Request.ContentType := '"application/json"'; 
     memo1.lines.Add( idhttp1.post('http://127.0.0.1:8332/', T)) 


     end; 

    end. 

也许我给累谁知道,但是这是推动了墙上:\上的RPC

文档客户端 https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29

用途:

超对象链接:http://www.progdigy.com/?page_id=6

回答

0

文档说与它通信时

基本接入认证必须 使用,并且, 安全性,默认情况下,服务器 只接受来自同一机器上其他 进程的连接。

因此,您的代码需要设置Indy请求对象的用户名,密码和BasicAuthentication属性。

(A缺失认证通常会导致,而不是400。HTTP 401(未授权))

+0

我忘了加我设置的属性编辑器已经USR /通! – Strspeed

1

400的意思是 “错误的请求”。您正在发送服务器无法处理的数据。尝试使用TIdHTTP.Post(TStream)而不是TIdHTTP.Post(TStrings)发送您的JSON数据。 TStrings版本以一种可能会改变JSON数据的方式对字符串数据进行编码,因此它不再是有效的JSON。 Post()的这个版本是用于'application/x-www-form-urlencoded'请求的。

试试这个:

procedure TForm2.Button1Click(Sender: TObject); 
var 
    O: Isuperobject; 
    Strm: TStringStream; 
begin 
    O := SO('{"jsonrpc": "1.0", "method": getinfo, "params": "[]" }'); 
    Strm := TStringStream.Create(O.AsString); 
    try 
    IdHTTP1.Request.ContentType := 'application/json'; 
    Memo1.Lines.Add(IdHTTP1.Post('http://127.0.0.1:8332/', Strm)); 
    finally 
    Strm.Free; 
    end; 
end; 
+0

仍然得到400错误,但你开悟了我,我应该知道这一点。即时即将在Tstream中尝试它作为Json对象。 – Strspeed