如何使用Synapse在TinyWebDB中存储值?

时间:2016-03-04 19:36:40

标签: json http-post lazarus app-inventor synapse

我正在尝试使用Synapse库在TinyWebDB组件(AppInventor)中存储一个值。我设法使用此代码获取值:

    procedure GetValue(Tag:String);
    var URL: string;
        Params: string;
        Response: TMemoryStream;

    begin
      Response := TMemoryStream.Create;

      try
        URL := 'http://appinvtinywebdb.appspot.com/getvalue';

        Params := 'tag=' + EncodeURLElement(Tag);

        if HttpPostURL(URL, Params, Response) then
          Response.SaveToFile('response.txt');

      finally
        Response.Free;
      end;
    end;

但我无法存储价值。任何想法或建议? 顺便说一句,我尝试通过添加另一个参数并格式化代码来存储值:

procedure StoreValue(Tag, Value: String);
var URL: string;
    Params: string;
    Response: TMemoryStream;

begin
  Response := TMemoryStream.Create;

  try
    URL := 'http://appinvtinywebdb.appspot.com/storevalue';

    Params := 'tag=' + EncodeURLElement(Tag)+'&'+
              'value='+ EncodeURLElement(Value);

    if HttpPostURL(URL, Params, Response) then
      Response.SaveToFile('response.txt');

  finally
    Response.Free;
  end;
end;

它似乎不起作用,因为响应文件为空。它应该包含这样的内容:

  

[“STORED”,“SomeTag”,“SomeValue”]

1 个答案:

答案 0 :(得分:1)

我明白了。除了URL之外,第二段代码正在运行。我使用的网址是

  

http://appinvtinywebdb.appspot.com/storevalue

而不是

  

http://appinvtinywebdb.appspot.com/storeavalue

结论:代码完美无缺,结果是[" STORED"," SomeTag"," SomeValue"]。