How to async this (if it has to be)?

Just starting out? Need help? Post your questions and find answers here.
jagermeister
Posts: 5
Joined: Thu Mar 24, 2016 10:51 pm

How to async this (if it has to be)?

Post by jagermeister »

This should be a simple request with XML string returned, but I don't get the result$ data back (though I do get header$ and <Records> tags). Probably rock bottom basic for you sorcerers. :P

SB page:

Code: Select all

Procedure HttpGetEvent(Success, Result$, UserData)
  If Success
    MessageRequester("Success" + Chr(10) + Chr(10) + Result$ , #PB_MessageRequester_Ok)
  EndIf
EndProcedure

url$ = "https://IIS_SRV/cgi-bin/relay.exe"
badge$ = "1001" ; for testing

HTTPRequest(#PB_HTTP_Post, url$ , "badge=" + badge$ , @HttpGetEvent())

PB listener:

Code: Select all

;-LIBRARIES

UseODBCDatabase()

;-Enumerations

Enumeration databases
  #odbc
EndEnumeration


Procedure.s query(b$)
  
  connection$ = "TEST_TABLE"
  
  Select OpenDatabase(#odbc , connection$ , "" , "")
    Case 0
      Debug "Connection failed: " + DatabaseError()
    Default
      Debug "Connected to database"
      
      query$ = "SELECT " +
               "badge," +
               "first_name," +
               "last_name," +
               "phone" +
               "FROM members " +
               "WHERE badge = '" + b$ + "';"
      
      Select DatabaseQuery(#odbc , query$)
        Case 0
          Debug "Query error: " + DatabaseError()
        Default
          fieldCount = DatabaseColumns(#odbc)
          
          While NextDatabaseRow(#odbc)
            For field = 0 To fieldCount-1
              result$ + "<" + DatabaseColumnName(#odbc , field) + ">" + 
                        GetDatabaseString(#odbc , field) +
                        "</" + DatabaseColumnName(#odbc , field) + ">"
            Next field
          Wend
          FinishDatabaseQuery(#odbc)
      EndSelect
      
      CloseDatabase(#odbc)
      
  EndSelect
  
  ProcedureReturn(result$)
  
EndProcedure


If Not InitCGI() Or Not ReadCGI()
  End
EndIf

badge$ = CGIParameterValue("badge")
result$ = query(badge$)

header$ = "<?xml version=" + #DQUOTE$ + "1.0" + #DQUOTE$ + " " + "encoding=" + #DQUOTE$ + "UTF-8" + #DQUOTE$ + "?>"

result$ = header$ + "<Records><Record>" + result$ + "</Record></Records>"

WriteCGIHeader(#PB_CGI_HeaderContentType, "application/xml" , #PB_CGI_LastHeader)
WriteCGIString(result$)
Last edited by jagermeister on Mon Oct 09, 2023 7:12 pm, edited 1 time in total.
plouf
Posts: 295
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: How to async this?

Post by plouf »

First is if you run your script from same exact domain
Since requesting from a diffirent domain is blocked from CORS policy

Second is server configuration is correct configured to execute .exe
Christos
jagermeister
Posts: 5
Joined: Thu Mar 24, 2016 10:51 pm

Re: How to async this?

Post by jagermeister »

Hello Plouf,

Yes, web server (IIS) and listener are on the same server, as well as the database (MSSQL). The listener has permissions to run, and does, and will return correct strings in PB debug. In production, however, only the parts of the string that are directly set like header$ are returned, while result$ remains blank. The final output:

Code: Select all

result$ = header$ + "<Records><Record>" + [b]result$[/b] + "</Record></Records>"
will only return

Code: Select all

<?xml version= "1.0" encoding="UTF-8"?><Records><Record></Record></Records>
on the web page.
jagermeister
Posts: 5
Joined: Thu Mar 24, 2016 10:51 pm

Re: How to async this?

Post by jagermeister »

*sigh*

Okay, it was my rusty brain. MSSQL needs to allow SQL authentication, have the login set up, and permission to the database, along with the listener using that login. Forgot about scope when it comes to web applications. :oops:

Made the changes and it's working beautifully.

Thank you, SB/PB friends!
Post Reply