Jump to content
Tom Wellige

Function: LaunchHTTPRequest

Recommended Posts

This post is taken from the Swyx Forum Archive (2007-2014) and was originally posted 27.04.2010 by me

 

This function calls (launches) a given URL (http request) and returns True if the request returns without error.

To use the function within your call routing script just copy&paste it into the "Start" block and call it afterwards within an "Evaluate" block.

 

'-------------------------------------------------------------------
' LaunchHTTPRequest
' 
' Launches given URL.
'
' Parameter:
'	sURL		complete url
'
' return value:
'	boolean		True  - request file processed
'				False - request file *not* processed
'--------------------------------------------------------------------
Function LaunchHTTPRequest(ByVal sURL)
	PBXScript.OutputTrace "------> LaunchHTTPRequest ( sURL = '" & sURL & "' )"

	On Error Resume Next

	Dim bReturn
	bReturn = True

	Dim HTTP_REQ
	Set HTTP_REQ = CreateObject("Msxml2.ServerXMLHTTP.3.0")

	Dim lResolve, lConnect, lSend, lReceive
	lResolve =  1 * 60 * 1000	' 1 minute (default: infinte)
	lConnect =  1 * 60 * 1000	' 1 minute (default)
	lSend    = 60 * 60 * 1000	' 1 hour   (default: 30 seconds)
	lReceive = 60 * 60 * 1000	' 1 hour   (default: 30 seconds)
	HTTP_REQ.setTimeouts lResolve, lConnect, lSend, lReceive

	Dim vBefore, vAfter, nDuration
	vBefore = Now
	HTTP_REQ.open "GET", sURL, False
	HTTP_REQ.send

	If Err <> 0 Then
		PBXScript.OutputTrace "Error sending http request (" & Hex(Err) & ")"
		PBXScript.OutputTrace Err.Description
		Err.Clear
	Else
		vAfter = Now
		nDuration = DateDiff("s", vBefore, vAfter)
		PBXScript.OutputTrace "HTTP Request returned after " & nDuration & " seconds"
		bReturn = True
	End If

	Set HTTP_REQ = Nothing

	LaunchHTTPRequest = bReturn

	PBXScript.OutputTrace "bReturn = " & bReturn
	PBXScript.OutputTrace "<------ LaunchHTTPRequest"
End Function

 

Share this post


Link to post
Share on other sites

Hello Tom,

 

do i have to install anything on my Windows server to use this script?

do i have to install this for it to work (https://support.microsoft.com/en-us/help/290761/frequently-asked-questions-about-serverxmlhttp)?

Msxml2.ServerXMLHTTP.3.0

because this script wont work on my windows 12 server.

 

Best regards Jakob H

Share this post


Link to post
Share on other sites

Hey Tom,

 

i found the error:

On 9/3/2019 at 9:51 PM, Tom Wellige said:

( sURL = '" sURL & "' )"

i had to change this to:

( sURL = "+ sURL & +" )"

Then i used your code to make an HTTP request to my own C# API to get the number from the on-call duty person with "HTTP_REQ.responseText".

 

Thank you for your awesome work in this forum!

 

With best regards Jakob H

Share this post


Link to post
Share on other sites

 

Hi there, I would like to call a URL for incoming calls, which should then save the number in a variable. I used your script for this. The number also arrives, but with +49 I would like 0049 instead of +49 is that possible?

Edited by Daniel A

Share this post


Link to post
Share on other sites
14 minutes ago, Daniel A said:

Hi there, I would like to call a URL for incoming calls, which should then save the number in a variable. I used your script for this. The number also arrives, but with +49 I would like 0049 instead of +49 is that possible?

 

What Client SDK API or SwyxIt! Variable are you using the get the caller number?

 

Share this post


Link to post
Share on other sites

Hi,

 

the function IpPbx.CallingNumber calls PBXCall.CallingPartyNumber which actually should return the caller number not in canonical (+49) but in the wanted format (0049).

 

The only reason I can think of at the moment, that you are getting the number in canonical format, is that you have the caller in the global/private phone book which sets the number internally then in canonical format.

 

Do you have the caller in your global/private phone book?

 

Share this post


Link to post
Share on other sites
1 hour ago, Tom Wellige said:

Hallo,

 

Die Funktion  IpPbx.CallingNumber ruft PBXCall.CallingPartyNumber auf, die die  Anrufernummer eigentlich nicht kanonisch (+49), sondern im gewünschten Format (0049) zurückgeben soll.

 

Der einzige Grund, an den ich im Moment denken kann, dass Sie die Nummer im kanonischen Format erhalten, ist, dass Sie den Anrufer im globalen / privaten Telefonbuch haben, das die Nummer intern und dann im kanonischen Format festlegt.

 

Haben Sie den Anrufer in Ihrem globalen / privaten Telefonbuch?

 

hello, I've tried it again. It always comes with +49 instead of 0049. No is not in the phone book. Is there no way to replace the variable beforehand? Sincerely, Daniel

Share this post


Link to post
Share on other sites

I little bit of VBScript code should do the trick:

 

Dim sCaller
sCaller = IpPbx.CallingNumber

If Left(sCaller, 1) = "+" Then
	sCaller = "00" & Right(sCaller, Len(sCaller)-1)
End If

or

Dim sCaller
sCaller = Replace(IpPbx.CallingNumber, "+", "00")

 

Afterwards you use "sCaller" in your URL instead of "IpPbx.CallingNumber".

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.