NetTalk Central

Author Topic: Calling a website with parameters from within nettalk  (Read 7331 times)

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Calling a website with parameters from within nettalk
« on: October 06, 2015, 07:07:41 AM »
Hi I have this code in Nettalk and it works, it opens the page as I expect:
p_web.Script(  P_web.WindowOpen('http://www.albertonday.co.za/albertonday-stalls_6.html') )
What I now  need to do is call a site that sends an SMS message to a nominated cell number.
The site requires parameters.An example of the line that I can enter directly into the URL is

https://www.winsms.co.za/api/batchmessage.asp?User=testuser&Password=stefan&Message=You can register&Numbers=27824410959

If I run this this the remote site completes the operation and returns a success or fail message

How can I integrate this into my webapp so that it completes the operation. I am not really interested in the result in this case since the fail would indicate that the user had entered a ficticious cell number and thus would be denied entry to the system.

I had thought to use the p_web.Script routine like this:
p_web.Script(  P_web.WindowOpen('https://www.winsms.co.za/api/batchmessage.asp?User=testuser&Password=stefan&Message=You can register&Numbers=27824410959') )
but it opens the site and the line is changed to:
https://www.winsms.co.za/api/batchmessage.asp?User=testuser&Password=stefan&Message=You%20can%20register&Numbers=27824410959
which doesn't happen with the straight URL entry and an error message Error="No message given" is returned

What I would like to achieve is to just call the url and continue with no result reported back.
Any advice appreciated

Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Calling a website with parameters from within nettalk
« Reply #1 on: October 06, 2015, 10:18:40 AM »
What I've tried so far:
I have created a window procedure called SendSMS
I have added a Nettalk simple Object called ThisWebClient
In the Open the Window embed

URL = 'https://www.winsms.co.za/api/batchmessage.asp?User=testuser&Password=stefan&Message=This message from Genweb&Numbers=27824410959'
ThisWebClient.Init()        !I got an error that Init() had not been called before open
ThisWebClient.SetAllHeadersDefault()
  ThisWebClient.CanUseProxy = 1                      !Added this
ThisWebClient._HTTPVersion = 'HTTP/1.1'
ThisWebClient.AsyncOpenUse = 1                     !Added this
ThisWebClient.AsyncOpenTimeOut = 1200
ThisWebClient.InActiveTimeout = 9000
ThisWebClient.HeaderOnly = 1
ThisWebClient.SSLMethod = NET:SSLMethodTLSv1_2
st.trace('b4fetchURL')
ThisWebClient.Fetch(URL)
st.trace('after fetchURL')
POST(Event:CloseWindow)

Basically I have stripped this out of The NetDemo WebClient app.
The 2 traces before and after The Fetch(URL) both appear in DebugView++
Using the WebClient in Netdemo the URL is fetched and the result is displayed.

I'm missing something obvious. What else should I be doing to get the application to Fetch the URL?
Updated
I put a trace in the .ErrorTrap routine and picked up that ThisWebClient.Init() hadn't been called so I added it to the above
I have a trace in both the .ErrorTrap and .PageReceived routines but neither is now accessed.
To simplify the issue I changed the URL to my personal website but still no response.
« Last Edit: October 06, 2015, 12:02:01 PM by terryd »
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Calling a website with parameters from within nettalk
« Reply #2 on: October 06, 2015, 01:50:34 PM »
Hi Terry,

I would actually try to get it working in the netdemo program first. I've found it easier in that environment to test various things and then port the solution across to my app when I understand how it works.

BTW I think it should be a post not a fetch. I would also move the POST(Event:CloseWindow) to after your trace in the page received method for testing.

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Calling a website with parameters from within nettalk
« Reply #3 on: October 07, 2015, 01:44:47 AM »
Hi Kevin
Thanks for the reply.
It does work in the NetDemo, see what I said here in my posting

Basically I have stripped this out of The NetDemo WebClient app.
The 2 traces before and after The Fetch(URL) both appear in DebugView++
Using the WebClient in Netdemo the URL is fetched and the result is displayed.

I would agree with you post versus Get comment except that it does work and return Data (See the attached addressfetch.jpg and logging.jpg images) in the Netdemo webclient procedure.
 
The netdemo is a windows based application whereas I am trying to implement this in a WebApplication which may be where my problem is. As far as I can see there are no demos of accessing webservices from within a webserver, lots about creating them but all the examples of consuming them are Windows based.

I have tried to emulate the way that SendEmail is implemented in the Web11 application.
I have created a SendSMS Window Procedure
I have placed st.trace messages in various locations in my app
Before the Fetch which will display the selected URL
After the fetch
In the send Procedure
In the PageReceived Procedure
In the ErrorTrap Procedure
If you look at the attached DebugviewLog.txt I have divided it into 2 sections. The first section is where I entered my own website address which worked. I received a PageString Message inside the received Procedure

In the second section I used the URL I would like to use (The username is changed from the actual username)
Here in the Sent Procedure It displays the sent values.
I receive the SMS (i.e. the Fetch works, it accessed the requested URL and sent the requested SMS), but it hangs at this point, the procedure doesn't pass to the PageReceived or ErrorTrap procedures


[attachment deleted by admin]
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Calling a website with parameters from within nettalk
« Reply #4 on: October 07, 2015, 02:02:32 PM »
Hi Terry,

I'm doing lots of API stuff from my web server so there is no difference being called from a webserver or windows program.

In the netdemo try putting in the full message that is shown in your trace: Message=Password reset. Your login is 0824410959 and your password is csgqj. Remember to change your password after login

and see if you still get a response from the other website

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Calling a website with parameters from within nettalk
« Reply #5 on: October 07, 2015, 08:00:11 PM »
Hi Kevin
Thanks for taking the time to look at my problem.
Please see the attached Netdemo screens where I have duplicated the message that I have generated from within my app.


[attachment deleted by admin]
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Calling a website with parameters from within nettalk
« Reply #6 on: October 07, 2015, 09:55:41 PM »
Hi Terry,

It all looks ok - I gather if the webclient window closed then it would all be working? Can you screen shot your PageReceived Routine?

I also noticed in my app ThisWebClient.init() is generated by the template so it might be your code is before this and then the code below is running after your code and causing a prob.

 
  ! End of "NetTalk Object Before Init Section"
  ThisWebClient.SuppressErrorMsg = 1         ! No Object Generated Error Messages ! Generated by NetTalk Extension
  ThisWebClient.init()
  if ThisWebClient.error <> 0
    ! Put code in here to handle if the object does not initialise properly
    ! Start of "NetTalk Object Init Failed Section"
    ! [Priority 5000]
   
    ! End of "NetTalk Object Init Failed Section"
  end



terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Calling a website with parameters from within nettalk
« Reply #7 on: October 08, 2015, 06:35:55 AM »
Hi Kevin
Yes if the client closed I would be happy. As I said the problem seem to be that it never arrives at PageReceived or ErrorTrap

I also saw that the documentation stated that the Webclient would be intialised and closed but when I ran the code I got an error Not initialised. After adding the init the app worked (sort of ;-)
Maybe the best is for me to layout what I have got:
I created a Window with 2 buttons
SendSMS and close
Added StringTheory object st
Added NetTalk or NetSimple Object BaseClass NetWebClient ObjectName ThisWebClient Settings Supress Error Messages

In WindowManager Init After opening the window
 Quickwindow{prop:hide} = 1
 post(event:accepted,?SMSSend)
In ?SMSSend Accepted
SMSMessage = pSMSMessage! 'This message is a speed SMS test from Genweb using a created URL'
SMSNumber = pSMSNumber!'27824410959'
URL = 'https://www.winsms.co.za/api/batchmessage.asp'
URL = CLIP(URL) & '?User=' & CLIP(gs:WinSMSUserName) & '&Password=' & CLIP(gs:WinSMSPassword)
URL = CLIP(URL) & '&Message=' & CLIP(SMSMessage) & '&Numbers=' & CLIP(SMSNumber)
!URL = 'http://www.davcomm.co.za'  !If I enable this line the app works as expected
st.Trace('URL ' & CLIP(URL)) !This generates the correct URL
ThisWebClient.Init()
ThisWebClient.SetAllHeadersDefault()
ThisWebClient.CanUseProxy = 1
ThisWebClient._HTTPVersion = 'HTTP/1.1'
ThisWebClient.AsyncOpenUse = 1
ThisWebClient.AsyncOpenTimeOut = 1200
ThisWebClient.InActiveTimeout = 9000
ThisWebClient.HeaderOnly = 0
!ThisWebClient.OptionDontRedirect = DontRedirect  !I have remmed this out in the application because it throws an error
ThisWebClient.SSLMethod = NET:SSLMethodTLSv1_2
ThisWebClient.Fetch(URL)

In ?Close
  post(event:closewindow)

Send Procedure
if self.packet.binDataLen > 0
    PageSent = self.packet.binData[1 : self.packet.binDataLen] & '<13,10>-----------------<13,10>' & PageSent
end
st.trace('Inside Send Page Sent: ' & SUB(PageSent,1,80))
st.trace('Inside Send Page Sent: ' & SUB(PageSent,81,80))
st.trace('Inside Send Page Sent: ' & SUB(PageSent,161,80))
st.trace('Inside Send Page Sent: ' & SUB(PageSent,241,80))

PageReceived
st.Trace('Inside received')
st.trace('Downloaded ' & ThisWebClient.PageLen & ' bytes')
PageString = ThisWebClient.Page [1 : ThisWebClient.PageLen]
st.trace('Page String ' & CLIP(PageString))
ThisWebClient.Kill()
POST(EVENT:CloseWindow)

ErrorTrap
st.Trace('inside error trap')
temp2 = self.InterpretError()
if self.error = 0
    temp2 = clip(errorStr) & '.'
else
    temp2 = clip(errorStr) & '.' & ' The error number was ' & self.error & ' which means ' & clip(temp2) & '.'
end
if self.error = ERROR:OpenTimeOut or (self.Error >= ERROR:SSLGeneralFailure and self.Error < ERROR:NetTalkObjectAndDLLDontMatch)
  ! Also list the WinSock or SSL Errors
    if self.WinSockError
        temp2 = clip(temp2) & ' - [WinSock Error = ' & self.WinSockError & ' : ' & clip (NetErrorStr (self.WinSockError)) & ']'
    end
    if self.SSLError
        temp2 = clip(temp2) & ' - [SSL Error = ' & self.SSLError & ']'
    end
end
st.trace('Error: ' & CLIP(temp2))


I appreciate the time you have spent looking at this.
« Last Edit: October 08, 2015, 06:37:50 AM by terryd »
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11239
    • View Profile
Re: Calling a website with parameters from within nettalk
« Reply #8 on: October 08, 2015, 07:29:45 AM »
Hi Terry,

>> ThisWebClient.Init()        !I got an error that Init() had not been called before open

I think this implies you are doing the code in the wrong place. I would put this code under a button, and then just do a Post(event:Accepted,?button) in the window open

>>  As I said the problem seem to be that it never arrives at PageReceived or ErrorTrap

Possibly as a side effect of the above.

Your original code;

ThisWebClient.Fetch(URL)
st.trace('after fetchURL')
POST(Event:CloseWindow)

Is clearly wrong though - you shouldn't post a Close:Window from here.

cheers
Bruce


terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Calling a website with parameters from within nettalk
« Reply #9 on: October 08, 2015, 09:02:30 AM »
Hi Bruce
Thanks for the reply
>> ThisWebClient.Init()        !I got an error that Init() had not been called before open

I think this implies you are doing the code in the wrong place. I would put this code under a button, and then just do a Post(event:Accepted,?button) in the window open
I thought that this is what I had done?
In WindowManager Init After opening the window
 Quickwindow{prop:hide} = 1
 post(event:accepted,?SMSSend)


I have removed the init - it compiles so originally I must have been in the wrong place.
I have also removed ThisWebClientKill()
and POST(Event:CloseWindow) From Page received

The application fetches the URL, the remote site issues an SMS but the focus seems to stay on the send procedure. If I do nothing a minute later a new SMS is sent.
Neither the trace in the PageReceived or errortrap procedures are touched
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Calling a website with parameters from within nettalk
« Reply #10 on: October 08, 2015, 10:12:10 PM »
Got it working ;-)
Added these 2 lines in SetAllHeadersDefault
self.ProxyConnectionKeepAlive = 0  ! Close the connection after each transaction
self.ConnectionKeepAlive = 0  ! Close the connection after each transaction

which then meant I got a message from PageReceived
The application didn't close so in the PageReceived embed (and ErrorTrap)
I added
POST(EVENT:CloseWindow)
Which returned me to the Calling procedure.
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186