PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → Problem with POST in REST WebService
Problem with POST in REST WebService
Iniciado por bw, 15,feb. 2018 13:37 - 2 respuestas
Miembro registrado
37 mensajes
Publicado el 15,febrero 2018 - 13:37
Hi

I just started working with REST webservice.

I sucessfully created created a RestWebservice with procedures to find,delete and add a record.

It works fine except that in the add record procedure, when in the product_name (string field) and I have a space between 2 words then the webservice fails (return code 400/404)

If the product name have no space the post operation works fine

What is the matter ? how to fix it ?

The code to execute the webservice looks like bellow

oRequest is restRequest // httpRequest
oResponse is restResponse //httpResponse
sprodut_name is string
sUrl_formated is string

// when there are spaces I a replace it with + sign
sprodut_name=NoSpace(Replace(EDT_Product_name," ","+"))

sUrl_formated =StringBuild("http://XXX.kalanda.info/My_rest/add_product/{%1}/{%2}/{%3}/{%4}/{%5}",EDT_Code,sprodut_name,EDT_unit,EDT_Value,EDTamount)

oRequest..URL = sUrl_formated

oRequest..Method = httpPost

oRequest..ContentType = "text/plain"

// Request content
oRequest..Content = [

]

// Runs the request and retrieves the response
oResponse =RESTSend(oRequest))

IF oResponse.StatusCode=200 THEN
Info("Gravou "+oResponse.StatusCode)
ELSE
Info("erro "+oResponse.StatusCode)
END



Thank in advance

Bastiaan
Publicado el 15,febrero 2018 - 14:22
Hi Bastiaan,

you are probably mssing a 'urlencode' to prepare your data.

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Ready for you: WXShowroom.com, WXReplication (open source) and now WXEDM
(open source)

More information on http://www.fabriceharari.com


Le 2/15/2018 à 7:37 AM, Bastiaan a écrit :
Hi

I just started working with REST webservice.

I sucessfully created created a RestWebservice with procedures to
find,delete and add a record.

It works fine  except that in the add record procedure, when in the
product_name (string field) and I have a space between 2 words then the
webservice fails (return code 400/404)

If the product name have no space the post operation works fine

What is the matter ?  how to fix it ?

The code to execute the webservice looks like bellow

oRequest is restRequest // httpRequest
oResponse is restResponse //httpResponse
sprodut_name is string
sUrl_formated is string

//   when there are spaces I a replace it  with + sign
sprodut_name=NoSpace(Replace(EDT_Product_name," ","+"))

sUrl_formated
=StringBuild("http://XXX.kalanda.info/My_rest/add_product/{%1}/{%2}/{%3}/{%4}/{%5}",EDT_Code,sprodut_name,EDT_unit,EDT_Value,EDTamount)


oRequest..URL = sUrl_formated
oRequest..Method = httpPost

oRequest..ContentType = "text/plain"

// Request content
oRequest..Content = [

]

// Runs the request and retrieves the response
oResponse =RESTSend(oRequest))

IF oResponse.StatusCode=200 THEN
    Info("Gravou "+oResponse.StatusCode)
ELSE
    Info("erro "+oResponse.StatusCode)
END



Thank in advance
Bastiaan
Miembro registrado
37 mensajes
Publicado el 15,febrero 2018 - 19:58
Hi Fabrice


I tried to URLencode the value of the paramenter used by the POST webservice like bellow

sprodut_name=URLEncode(sprodut_name,encodeURLParameter)

And also tried to URLencode the whole URL after it was finished with all values, like bellow

sUrl_formated =StringBuild("http://XXX.kalanda.info/My_rest/add_product/{%1}/{%2}/{%3}/{%4}/{%5}",EDT_Code,sprodut_name,EDT_unit,EDT_Value,EDTamount)

sUrl_formated = URLEncode(sUrl_formated)


But the problem remain the same, , when in the product_name (string field) I have a space between 2 words then the webservice fails (return code 400/404), otherwise it works !


I really don`t know what to do...


By the way I am using Webdev 22