GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEV
,
WEBDEV
e
WINDEV Mobile
Inicio
|
Mensagens recentes
|
Conecte-se...
|
Disconnect
|
Português
Inicio
→
WINDEV 2024
→
API (REST) Request
API (REST) Request
Iniciado por Kim O'Regan, dez., 05 2019 11:32 AM - 6 respostas
Conecte-se…
Kim O'Regan
#1
Publicado em dezembro, 05 2019 - 11:32 AM
Hi all,
I'm trying to figure out how to create an API-request in Windev.
The request looks like this:
<?xml version='1.0' encoding='ISO-8859-1'?>
<marathon>
<password>abc123</password>
<type>api_operation</type>
<company_id>ABC</company_id>
<employee_id>ABC123</employee_id>
<date>2019-12-04</date>
<repeat_until></repeat_until>
<client_id>ABC</client_id>
<project_no>123</project_no>
<feecode_id>123</feecode_id>
<hours>4,5</hours>
<full_time_percentage></full_time_percentage>
<comment>ABC-1234 Working</comment>
</marathon>
Which is posted to:
"
https://adress_of_webservice
"
How would I do this in Windev?
Thankful for any help
Regards
/Kim
Denunciar
0
0
Jeroen de Jonge
#2
Publicado em dezembro, 05 2019 - 1:01 PM
Try this:
s
Xml
is string
= [
<?xml version='1.0' encoding='ISO-8859-1'?>
<marathon>
<password>abc123</password>
<type>api_operation</type>
<company_id>ABC</company_id>
<employee_id>ABC123</employee_id>
<date>2019-12-04</date>
<repeat_until></repeat_until>
<client_id>ABC</client_id>
<project_no>123</project_no>
<feecode_id>123</feecode_id>
<hours>4,5</hours>
<full_time_percentage></full_time_percentage>
<comment>ABC-1234 Working</comment>
</marathon>
]
Req
is httpRequest
c
Req.URL
=
https
:
//adress_of_webservice"
c
Req
..
ContentType
=
"application/xml"
//or "text/xml"
c
Req
..
Method
=
httpPost
c
Req
..
Content
=
s
Xml
//cReq.Header["x-auth-token"] = "???" //optional: sometimes needed for authentication
c
Resp
is httpResponse
=
HTTPSend
(
c
Req
)
SWTICH
c
Resp
..
StatusCode
CASE
200
//OK
OTHER
CASE
//cResp..Content contains more info
END
Denunciar
0
0
Kim O'Regan
#3
Publicado em dezembro, 05 2019 - 3:13 PM
Hi and thanks for the answer Jeroen.
Your example worked when I put in the XML-request in the sXml brackets.
The "problem" is that I will be reading rows from a database and sending them with httpPost.
So some of the values has to be variables. How do I achieve that?
Functioning:
sXml is string = [
<?xml version='1.0' encoding='ISO-8859-1'?>
<marathon>
<password>abc123</password>
<type>api_operation</type>
<company_id>ABC</company_id>
<employee_id>ABC123</employee_id>
<date>2019-12-04</date>
<repeat_until></repeat_until>
<client_id>ABC</client_id>
<project_no>123</project_no>
<feecode_id>123</feecode_id>
<hours>4,5</hours>
<full_time_percentage></full_time_percentage>
<comment>ABC-1234 Working</comment>
</marathon>
]
cReq is restRequest
cReq.URL = "
https://webservice_server
"
cReq..ContentType = "application/xml" //or "text/xml"
cReq..Method = httpPost
cReq..Content = sXml
//cReq.Header["x-auth-token"] = "???" //optional: sometimes needed for authentication
cResp is restResponse = HTTPSend(cReq)
Regards
/Kim
Denunciar
0
0
Jeroen de Jonge
#4
Publicado em dezembro, 06 2019 - 2:20 PM
Try this:
xmlDoc
is xmlDocument
xmlDoc
..
Encoding
=
XMLEncodingUTF8
xmlDoc.marathon.password
=
"abc123"
xmlDoc.marathon.type
=
"api_operation"
xmlDoc.marathon.company_id
=
"ABC"
xmlDoc.marathon.employee_id
=
"ABC123"
xmlDoc.marathon.date
=
"2019-12-04"
xmlDoc.marathon.repeat_until
=
""
xmlDoc.marathon.client_id
=
"ABC"
xmlDoc.marathon.project_no
=
123
xmlDoc.marathon.feecode_id
=
123
xmlDoc.marathon.hours
=
4.5
xmlDoc.marathon.full_time_percentage
=
""
xmlDoc.marathon.comment
=
"ABC-1234 Working"
c
Req
is httpRequest
c
Req.URL
=
"https://adress_of_webservice"
c
Req
..
ContentType
=
"application/xml"
//or "text/xml"
c
Req
..
Method
=
httpPost
c
Req
..
Content
=
XMLBuildString
(
xmlDoc
,
XMLDocumentDefault
)
//cReq.Header["x-auth-token"] = "???" //optional: sometimes needed for authentication
c
Resp
is httpResponse
=
HTTPSend
(
c
Req
)
SWITCH
c
Resp
..
StatusCode
CASE
200
//OK
OTHER
CASE
//cResp..Content contains more info
END
Denunciar
0
0
Kim O'Regan
#5
Publicado em dezembro, 06 2019 - 4:46 PM
Hi and thanks for the answer, again, Jeroen!
I will try this.
/Kim
Denunciar
0
0
Kim O'Regan
#6
Publicado em dezembro, 09 2019 - 4:36 PM
Hi Jeroen,
I get this when running the script:
"Failure retrieving the XML.
unknown encoding 2
.content"
Tried the "text/xml" to no prevail.
The Content seems to be empty.
What's missing?
Regards
/Kim
Denunciar
0
0
Kim O'Regan
#7
Publicado em dezembro, 10 2019 - 7:01 PM
Hi,
I've managed to implement the XML-part into my application. So now it sends and stores the info in the database.
I do though have a "small" problem. I use time in my application which is formatted hh:mm.
The recieving system use either hh,mm or hh.mm and, e.g 1:30 is displayed 1,5 or 1.5 on the recieving system.
How do I convert e.g 1:30 to 1,5?
Regards
/Kim
Denunciar
0
0
→ Voltar para WINDEV 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (versões anteriores)
Français
English
Español
Portuguesa
Fermer cette fenêtre
Tipo de Pesquisa
Apenas tópicos
Todas as mensagens
Período de pesquisa
Qualquer momento
Última hora
Últimas 24 horas
Semana passada
Mês passado
Ano passado
Cancelar
Pré-visualização da sua mensagem
Adicionar imagem
Importar uma imagem de uma URL
Enviar uma imagem a partir do seu disco
Deixe um ficheiro ou clique em "Procurar ..."
ou
Cancelar
0%
WLanguage
SQL
XML, HTML
JAVA, Javascript
Texto