Ewon TechForum
Providing technical solutions to technical requests


Correct use of REQUESTHTTPX
LennonEletronor Offline
Junior Member
#1
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_v...aquina=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?
Reply

LennonEletronor Offline
Junior Member
#2
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
Reply

simon Offline
eWON Support
#3
Strange...
On my side, it works good :


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

I use the firmware 14.0s02

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

Simon
Reply

djonedd Offline
Junior Member
#4
(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: "{"email" : ".....@....com", "password" : "asd!@#"} 
Do you have some document for special character? thank you

Joned
Reply

simon Offline
eWON Support
#5
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
Reply

sheeran Offline
Junior Member
#6
(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!
Reply

simon Offline
eWON Support
#7
Hi,

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

I have tried myself and it works fine
Reply



Possibly Related Threads…
07-11-2019, 03:33 PM
Last Post: simon
  RequestHTTPX error Started by fvantour
1 Replies - 1.272 Views
23-10-2018, 01:14 PM
Last Post: fvantour
16-11-2017, 07:06 AM
Last Post: timon
  REQUESTHTTPX Doesn't arrive on server Started by rafaello104
5 Replies - 2.689 Views
28-10-2017, 09:14 AM
Last Post: simon



Users browsing this thread:
1 Guest(s)



Theme © Ewon 2019 - Forum software by © MyBB - Cookie policy