VBScript is unable to make webservice call


I am not able to make a call to API service from AFL using VBScript. Same HTTP post call I was able to successfully make it using PostMan, but not from AFL. Its not even throwing any error. Also, I checked the response and I got some text which was in Chinese which I couldn't understand. Please help.

Is there any other better way to make HTTP Post calls using Amibroker. I am using Amibroker 6.2.

Below is the source code called ServiceLib.afl, which I have placed in the include folder.

_SECTION_BEGIN("Service Library 1.0");


SERVICE_URI = ParamStr("Service URI","http://localhost:50607/api/messages");
SERVICE_AUTHORIZATION_CODE = ParamStr("Service Authorization Code","OMSUX-001");
SERVICE_AUTHORIZATION_KEY = ParamStr("Service Authorization Key","7ca134b4-4905-442b-a3f2-9616d315dc1f");
SERVICE_STRATEGY_CODE = ParamStr("Service Strategy Code","GUD01");


Public Sub ServiceCall(SymbolName, OrderType)

strJSON = "{""AuthorizationCode"":""" & AFL("SERVICE_AUTHORIZATION_CODE") & """,""AuthorizationKey"":""" & AFL("SERVICE_AUTHORIZATION_KEY") & """," & _
					 """StrategyCode"":""" & AFL("SERVICE_STRATEGY_CODE") & """,""SymbolName"":""" & SymbolName & """,""OrderType"":" & OrderType & "}"

'MsgBox strJSON, vbOK, "ServiceCall"
Dim objXmlHttpMain

set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP") 
on error resume next 
objXmlHttpMain.open "POST", AFL("SERVICE_URI"), False
objXmlHttpMain.setRequestHeader "Content-Type", "application/json"

objXmlHttpMain.send strJSONToSend

'MsgBox objXmlHttpMain.responseBody

set objXmlHttpMain = nothing

If Err.Number <> 0 Then
  MsgBox  "Error: " & Err.Description
End If

'MsgBox strJSON, vbOK, "ServiceCall"

End Sub 


function SendOrder(OrderType)
	local type, SymbolName;
		case 1:
		case 2:
		case 3:
		case 4:
	vbScriptObject = GetScriptObject(); 
		vbScriptObject.ServiceCall(SymbolName, OrderType);
	if (LastValue(ValueWhen(Ref(Buy,-1),BarIndex())==BarIndex()) AND StaticVarGet(SymbolName+GetChartID()+type+"Alert")==0 )
		vbScriptObject = GetScriptObject(); 
		vbScriptObject.ServiceCall(SymbolName, OrderType);
		StaticVarSet(SymbolName + GetChartID() + type+"AlertBar", LastValue(TimeNum()));
	if (LastValue(TimeNum()) == StaticVarGet(SymbolName+GetChartID()+type+"AlertBar"))
		StaticVarSet(SymbolName+GetChartID()+type+"Alert",1); //alert was triggered, no more alerts on this bar
		StaticVarSet(SymbolName+GetChartID()+type+"Alert",0); // new bar formed, and alerts can be trigered.
function SendBuyOrder() {
function SendSellOrder() {
function SendShortOrder() {
function SendCoverOrder() {


This is how I am calling in my main AFL file at the end.

SEND_ORDERS = ParamToggle("Send Live Orders?", "NO|YES");

#include_once "Formulas\Include\ServiceLib.afl";

	if(LastValue(Buy)) {
	} else if(LastValue(Sell)) {
	} else if(LastValue(Short)) {
	} else if(LastValue(Cover)) {

Yes there is: RFC: InternetPostRequest

Hi Tomasz,

Can it be done in 6.2 or 6.0? I knew about InternetPostRequest. HOw to achieve in older versions of Amibroker? Is it possible to use any other technique for older versions?

6.30 upgrade in general is definitely worth it and 6.30.4 is the minimum for that function.

As an alternative, you can try the CreateObject() way using either XMLHTTP or ServerXMLHTTP MS objects ie. whichever suits your need.
This should work in older versions although i haven't tested myself.

I am trying to avoid using CreateObject. Is it possible to use Amibroker Development Kit and build a function using Curl++ for making HTTP calls and use that in AFL? Also, can you point me to an article on how to build a simple plugin using ADK (I did go through the documentation, but didn't find info on how to call the plugin from AFL)? I have already downloaded ADK from the downloads section.

My answer now is just loosely based on what i undesrstand mostly from TJs replies.

I dont know why you would go the DLL way, as even those AFL function calls will be locked by critical section.
What is the reason to avoid CreateObject? Anyway, TJ mentioned another way by runnning a local server also that you can use instead.

go through it properly, and also study the sample codes. There are many details explained directly in the sample codes contextually that are not in the general doc.

Maybe you can explain, but i have no idea as to what performance gain you will be targeting with the plugin when something is already implemented with so many checks as a built-in fn.

Just upgrade to 6.30 that is simple answer and solution.