Switch to desktop version  
Correct use of REQUESTHTTPX - Printable Version

+- Ewon Technical Forum (https://techforum.ewon.biz)
+-- Forum: Development (https://techforum.ewon.biz/forum-50.html)
+--- Forum: BASIC Script (https://techforum.ewon.biz/forum-52.html)
+--- Thread: Correct use of REQUESTHTTPX (/thread-1148.html)



Correct use of REQUESTHTTPX - LennonEletronor - 22-01-2020

I'm trying to use the function REQUESTHTTPX, but I think I'm using the wrong format.
I'm just trying to ping the server through the flexy.
The path below is what I'm trying to reach:

https://homolog.sonepar.com.br:7070/ms_vm/?req=ping&idEmpresa=60&maquina=103

The command that I'm using is:
Code:
REQUESTHTTPX "https://homolog.sonepar.com.br:7070/ms_vm/", "?req=ping&idEmpresa=60&maquina=103"

What I'm doing wrong?


RE: Correct use of REQUESTHTTPX - LennonEletronor - 24-01-2020

Code:
request:
REQUESTHTTPX "http://www.google.com","GET"
actionID% = GETSYS PRG,"ACTIONID"
PRINT "request actionid is "; actionID%
END

onEvent:
eventId% = GETSYS PRG,"EVTINFO"
IF (eventId% = actionID%) THEN 
  SETSYS PRG,"ACTIONID",eventId% 
  stat% = GETSYS PRG,"ACTIONSTAT" 
  IF (stat% = 0) THEN   
    GOTO response 
  ELSE   
    PRINT "Error (ERROR = "+Str$(stat%) + ")" 
  ENDIF
ENDIF
END

response:
a$ = RESPONSEHTTPX "STATUSCODE"
PRINT "***status: "; a$
a$ = RESPONSEHTTPX "HEADER"
PRINT "***all headers: "; a$
a$ = RESPONSEHTTPX "HEADER", "Server"
PRINT "***server header: "; a$
a$ = RESPONSEHTTPX "RESPONSE-BODY"
IF (Len(a$) < 1000) THEN 
  PRINT "***response body: "; a$
Else 
  PRINT "***response body size: "; Len(a$)
ENDIF
END
Hello, 
I'm still trying to undertand what I'm doing wrong. 
When I try to use the script above I receive this:

request actionid is 303

***status: ???

***all headers: ???

***server header: ???

***response body: ???


There are some errors in my code?
Thanks


RE: Correct use of REQUESTHTTPX - simon - 30-01-2020

Strange...
On my side, it works good :


  2020-01-30_12-33-18.png (Size: 54,26 KB / Downloads: 81)

I use the firmware 14.0s02

The only thing I have added is the ONSTATUS "GOTO onEvent" at the beginning.

Simon


RE: Correct use of REQUESTHTTPX - djonedd - 18-03-2020

(30-01-2020, 01:34 PM)simon Wrote: Strange...
On my side, it works good :



I use the firmware 14.0s02

The only thing I have added is the ONSTATUS "GOTO onEvent" at the beginning.

Simon
Hi Simon,

I have a little problem on "DATA POST" field
The customer need a raw data, but when i use:
$DATAPOST$ =  "{\"email\" : \".....@....com\", \"password\":\"asd!@#\"}" 
the output always error
when i use postman, the data should be like: [font=Tahoma, Verdana, Arial, sans-serif]"{"email" : ".....@....com", "password" : [/font][font=Tahoma, Verdana, Arial, sans-serif]"asd!@#"} 
Do you have some document for special character? thank you

Joned
[/font]



RE: Correct use of REQUESTHTTPX - simon - 19-03-2020

Hi,

The \ to escape characters does not work in BASIC.
In your case, you have to use single quote ' to define your string value : '{"email" : ".....@....com", "password" : "asd!@#"}'

Simon


RE: Correct use of REQUESTHTTPX - sheeran - 31-03-2020

(30-01-2020, 01:34 PM)simon Wrote: Strange...
On my side, it works good :



I use the firmware 14.0s02

The only thing I have added is the ONSTATUS "GOTO onEvent" at the beginning.

Simon
Hi, Simon,

I have tried what you have done, but the script keep throwing out Error code: 32603

Here is my code:

Code:
Init Part:

TSET 1, 50
ONTIMER 1, "Goto request"


Rem --- eWON user (end)
End
Rem --- eWON end section: Init Section
Rem --- eWON start section: test
Rem --- eWON user (start)
request:
  REQUESTHTTPX "https://virtserver.swaggerhub.com/sheeranchan/test/1.0.0/pet/0","GET"
  actionID% = GETSYS PRG, "ACTIONID"
  PRINT "request action id is "; actionID%
  ONSTATUS "GOTO onEvent"
END
onEvent:
  eventId% = GETSYS PRG, "EVTINFO"
  PRINT "event id is "; eventId%
  IF (eventId% = actionID%) THEN
    SETSYS PRG, "ACTIONID", eventId%
    stat% = GETSYS PRG, "ACTIONSTAT"
      IF (stat% = 0) THEN
        GOTO response
      ELSE
        PRINT "Error (ERROR = "+Str$(stat%) + ")"
      ENDIF
  ENDIF
END
response:
  a$ = RESPONSEHTTPX "STATUSCODE"
  PRINT "status: "; a$
  a$ = RESPONSEHTTPX "HEADER"
  PRINT "all headers: "; a$
  a$ = RESPONSEHTTPX "HEADER", "Server"
  PRINT "server header: "; a$
  a$ = RESPONSEHTTPX "RESPONSEBODY"
    IF (Len(a$) != 0) THEN
      PRINT "response body: "; a$
    Else
      PRINT "response body size: "; Len(a$)
    ENDIF
END



I can get the response from browser or command line normally, the openAPI is from Swagger and this is just a test:
Code:
//API response
{
  "id" : 0,
  "category" : {
    "id" : 0,
    "name" : "string"
  },
  "name" : "doggie",
  "photoUrls" : [ "string" ],
  "tags" : [ {
    "id" : 0,
    "name" : "string"
  } ],
  "status" : "available"
}


Could you have a look and see what I have done wrong here please? Any help will be appreciated, thanks!


RE: Correct use of REQUESTHTTPX - simon - 02-04-2020

Hi,

To read the body, it is
a$ = RESPONSEHTTPX "RESPONSE-BODY"

I have tried myself and it works fine


RE: Correct use of REQUESTHTTPX - simon - 01-09-2020

Hi,

You can try this as S3:

"Content-type= text/html; charset=utf-8"


RE: Correct use of REQUESTHTTPX - hermeja - 04-09-2020

no data reaches the backend in a node js application. I need an example of type POST

my request is

REQUESTHTTPX "https://midominio.com/api/variables","POST","Content-Type:  application/json; charset=utf-8","nombres=carlos&apellidos=sanchez&fecha=27/08/2020 18:01:00"

doesn't work


RE: Correct use of REQUESTHTTPX - simon - 10-09-2020

Hi,

The header format must "Parameter = Value", not "Parameter : Value"
So "Content-type=text/html"
I know it is weird ;-)

Simon