VFP can also be used as a front-end, cats and cats have gone through countless detours to summarize this entry to BS

Keywords: Operation & Maintenance server VFP

Debug Server Usage

Open Framework Project File
Run Environment Settings.prg
Run the debug server to start.
Default port is 801, IP is the IP of the development machine

Test Debug Server

With the debugging server open, you can open the browser (recommended for 360 Speed, Google Browser)
input http://192.168.0.99:801/1.fsp Modify IP based on development machine
127.0.0.1 is also available for the same machine


The words above indicate that the debugging server is working well.

Some conventions for Web site URL s and development frameworks

http://192.168.0.99:801/a1send.fsp?proc=Send
192.168.0.99 is an IP address, if you have a domain name you can change it to a domain name
801 is the HTTP service port
1.Fsp calls a1send.prg using FSP as the call file name
a1send class
The proc=Send parameter calls the method of the a1send class

Write a controller class

Controller class is an interface class that interacts with the BS front end

Definition of A1send class

Define Class a1send As Session  Procedure Send  Return "Hello world"  EndprocEnddefine

Browser input on call http://127.0.0.1:801/a1send.fsp?proc=sendJson
You can see the output JSON.
You can also use POSTMAN to test.

Server receives GET parameters

* -- WebApi controller class
*--Specification: The file name is the same as the class name. For example, class name: 1Send, file name 1Send.prg
*--Call Format http://ip: Port number/class name.fsp?proc=class procedure name
*--http parameterized get-style parameterized splicing in url
*--Value is passed in by &key=value pair, which can be spliced together http://ip: Port number/class name.fsp?proc=class procedure name&parameter 1=parameter value

Define Class a2get As Session    *--Pass-through key1=test     Procedure get    cResult=httpqueryparams("key1",this.iconnid)    cResult1=httpqueryparams("key2",this.iconnid)    RETURN "The parameter you passed is:"+cResult+cResult1    ENDPROC
Enddefine

Browser input on call http://127.0.0.1:801/a2get.fsp?proc=get&key1=test&key2=123
Is the first key-value pair used for the parameter? Connect, the second connect later with &Connect.
You can also use POSTMAN to test.

Description of POST Passage

BS parameters are passed in key-value pairs, JSON and other formats.
Only key-value pairs can be passed in URL s (GET mode).
POST can be placed in Body to send JSON, key-value pairs, and other formats.

Acceptance of key-value pair formats

VFP Backend Received with HttpQueryParams

JSON or other formats

Received as-is with HttpGetPostData and parsed by itself.

Server Receives Post Passwords

The following code is placed in the controller class of a3post, accepts all the POST data sent and returns it

Procedure Post    LOCAL cPostData    cPostData=HttpGetPostData(this.iconnid)    RETURN cPostData  Endproc   *--Parse key-value pair format name=Zhang San&age=21  Procedure PostParams    LOCAL cname,cage    cname=httpqueryparams("name")    cage=httpqueryparams("age")    RETURN "Full name:"+cname+"Age:"+cage  Endproc

Because there is no way to do POST tests in the browser address bar, we use the POSTMAN tool to assist with the test.

As shown in the figure above, after entering the URL and parameters, press the Send key to test.

VFP as Controller Class for Front End Call Back End

Dead work
1 Client project and server project should be separated into different folders
2 Open the corresponding project with two VFP s
3Client first runs environment settings, then runs debug server and shuts down debug server
4 It is OK for the server to run environment settings before running debug server

VFP Client Pass By Get

cUrl="http://127.0.0.1:801/a2get.fsp?proc=get"+"&key1="+"12345"WebClient=Newobject("Qiyu_HttpClient","Qiyu_HttpClient.prg")cData=WebClient.send(cUrl)If !Isnull(cData)    Messagebox(cData,11)Else    Messagebox(WebClient.msg)Endif

VFP Client Pass By POST

Post arguments can be either passed directly with a URL or in a Post(URL, key-value pair)

cUrl="http://127.0.0.0.1:801/a3post.fsp?Proc=PostParams "WebClient=Newobject ("Qiyu_HttpClient","Qiyu_HttpClient "," Qiyu_HttpClient.prg ") WebClient.method=" post "WebClient.setHeader (" content-type ","content-type "," application/x-www-form-urlencoded ") &&key pair form submit cData=WebClient.application form form form form form form form form form form form form form form form form form form form form form submitted cData=WebClient.send(name=three&age=21") If (cData) Isll Message Box (Message Elnuse) Message box (Message Elbox (WebClient.msg)Endif

Qiyou Framework JSON Format Convention

Success (other information can also be put in the string)
{" errno " :0, " errmsg " : " ok "}
fail
{errno: 1,'errmsg':'error message'}

Give an example
{Erno: 1,'errmsg':'File'1.prg'does not exist.','success':'false','errorMsg':'File'1.prg' does not exist. Procedure: socketweb1._onread, line number: 171,'total':'0','rows':'\"192.168.0.99:801 \"}

 

 

Posted by pleisar on Sun, 21 Nov 2021 09:40:45 -0800