#1 mORMot 1 » Json to DataSet is error, 0.0 is not a valid timestamp » 2017-04-01 01:47:42

Ericshen
Replies: 1

hi, ab :


In MSSQL 2012 Record date looks like  :

userid    nick        classid    FName    edate
3113281    3113281    1    test           2017-03-31 14:33:40.843

I used  Execute funtion  Got  the RawJSON data  from MSSQL  , and then I uesed JSONToDataSet for json to Dataset is error.  return error  :  0.0 is not a valid timestamp

var
   IR: IRemoteSQL;
   i : integer;
   ts,te: Long;
begin
  ts :=   GetTickCount ;
  if Assigned(Client) then
  begin
    if Client.Services['RemoteSQL'].Get(IR) then
    begin
      ds1.DataSet := JSONToDataSet(self,(IR.Execute(aSQL,True,False)));  //aSQL :='select * from table' 
    end;
  end;
  te :=GetTickCount;

  Memo1.Lines.Add('use time(s):'+inttostr(te - ts)) ;


This was developed with Delphi 10 berlin on Windows  10

thanks !

#2 Re: mORMot 1 » replace TIdHTTPRequestInfo to the mORMot » 2017-03-15 15:04:50

igors233, Thank you very much for your reply!

The url:http://127.0.0.1/wxapi? Wid=1 access Web services, then the server receives the request, access to such data: /wxapi=1? &signature=aaaaa&echostr=bbbbb&timestmp=cccc, now I want to break out of the data, such as: wxapi=1; signnature = aaaaa; timestmp=cccc;
how to deal with mormot?

#3 Re: mORMot 1 » replace TIdHTTPRequestInfo to the mORMot » 2017-03-15 07:56:55

igors233,Thank you for your reply!

Sorry, I may not have a clear description, the establishment of a mormot service, and then send a get request to fill in the external URL, and with four parameters: Signature, Timestamp, Nonce, Echostr; according to the value of these parameters, the need to check the mormot service request is not legitimate.
If checksum is returned by true.

#4 Re: mORMot 1 » replace TIdHTTPRequestInfo to the mORMot » 2017-03-15 05:18:42

thanks igors233!
I Visited http://127.0.0.1/wxapi?wid=1  and then I want get the values Wid=1 ,and other Return values  like  this: signature := ARequestInfo.Params.Values['signature'];
    timestamp := ARequestInfo.Params.Values['timestamp']; nonce := ARequestInfo.Params.Values['nonce'];

#5 mORMot 1 » replace TIdHTTPRequestInfo to the mORMot » 2017-03-15 01:16:33

Ericshen
Replies: 7

hell everyone , In my  demo I used the indy, now I want replace  TIdHTTPRequestInfo  to the mORMot .
how to it ? thanks!

code like this :

function CheckSignature(ARequestInfo: TIdHTTPRequestInfo): boolean;
var
  signature, timestamp, nonce, echostr: String;
  tmpstr: TStringList;
  temp: String;
begin
  tmpstr := TStringList.Create;
  try
    signature := ARequestInfo.Params.Values['signature'];
    timestamp := ARequestInfo.Params.Values['timestamp'];
    nonce := ARequestInfo.Params.Values['nonce'];

    echostr := ARequestInfo.Params.Values['echostr'];
    tmpstr.Add(Token);
    tmpstr.Add(timestamp);
    tmpstr.Add(nonce);
    tmpstr.Sort;
    temp := StringReplace(tmpstr.text, #13#10, '', [rfReplaceAll]);
    Result := SHA1(temp) = signature;
  finally
    tmpstr.Free;
  end;
end;


delphi berlin update 2, win 10

thanks!

#6 Re: mORMot 1 » Client only. Send JSON data via http Post. Receive and parse JSON. » 2017-03-03 03:49:18

Thanks mpv , I use TWinHttpAPI class for  fclient  is OK.

#7 Re: mORMot 1 » Client only. Send JSON data via http Post. Receive and parse JSON. » 2017-03-03 03:19:09

I Just use the http post function ,but there is a error : winhttp.dll error 12030.

compile in delphi 10.1,  win 10.

Url := Format(https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s',[aToken])

procedure testpost(URL: string);
var
  fclient : TWinHTTP;
  URI : TURI;
  aToken,MenuJson : string;
  FHeader, FData  :SockString;
begin

  MenuJson :=
  '{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},'+
  '{"type":"view","name":"视频","url":"http://v.qq.com/"},{"type":"click","name":"赞一下我们","key":"V1001_GOOD"}]}]}';

  URI.From(URL);

  FClient := TWinHttp.Create(URI.Server, URI.Port, False);

  FClient.Request(URL, 'POST', 0, '', MenuJson, 'application/json', FHeader, FData);
end;

#8 Re: mORMot 1 » I want use mormt to instead of NetHttpClient » 2017-03-03 00:51:58

Thank esmondb and thank ab again!  I Got  it ,used ok!

#9 Re: mORMot 1 » I want use mormt to instead of NetHttpClient » 2017-03-03 00:43:03

Thanks ,ab

my code complier on delphi 10.1 and win 10 64

#10 mORMot 1 » I want use mormt to instead of NetHttpClient » 2017-03-02 07:41:14

Ericshen
Replies: 5

Hi ab,


I would like use mormot to  callback another web site for his web API?   how to use?

Thank you

like this:

aURL : [url]https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=%s[/url]

function HTTP_Request(aURL, UTF8:string; RequestMode: string): AnsiString;
var
   MyHttp : TNetHTTPClient;
   aUTF8: TStringStream;
begin
   Result := '';
   MyHttp := TNetHTTPClient.Create(nil);
   aUTF8 := TStringStream.create;
   try
      with MyHttp do
      begin
          aUTF8.Clear;
          ConnectionTimeout := 2000;
          ResponseTimeout  := 10000;
          AcceptCharSet  := UTF8;
          AcceptEncoding := '65001';
          AcceptLanguage := 'zh-CN';
          ContentType := 'text/Html';
          try
            if LowerCase(RequestMode) = 'get' then
               Get(aURL,aUTF8)
            else
            if LowerCase(RequestMode) = 'set' then
              exit;// Post(aURL);
            Result := aUTF8.DataString;
          except
            on E: Exception do
              showmessage(e.Message);
          end;
      end;
   finally
     FreeAndNil(MyHttp);
     FreeAndNil(aUTF8);
   end;
end;

Board footer

Powered by FluxBB