开发者

communication with rpc service using indy HTTP client and Superobject DELPHI http 400 error code

Ok im stumped the following code gives me a http 400 error which tells me there is something wrong with the submitted data but i cant figure out what!:(

the client is set to encode URL (Ive tried both true/false);

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.

Maybe im to Tired who knows but this is driving off the wall :\

Documentation on the RPC client https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29

USES:

Superobject Link : http://www.progdigy.com/?page_id=6


400 means "Bad Request". You are sending data that the server cannot process. Try sending your JSON data using TIdHTTP.Post(TStream) instead of TIdHTTP.Post(TStrings). The TStrings version encodes the string data in a way that will likely alter the JSON data so it is not valid JSON anymore. That version of Post() is meant for 'application/x-www-form-urlencoded' requests instead.

Try this:

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;


The documentation says

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.

So your code needs to set the Username, Password and BasicAuthentication properties of the Indy Request Object.

(A missing authentication normally causes a HTTP 401 (Unauthorized) instead of a 400.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜