I'm trying to use vba to post to a web api. The problem is that the parameter is blank in the web api. The web api is written in asp. I called the api from c# and it works but I can't get it to work from vba.
Here is the vba call to the api:
Sub Test()
Dim http As New MSXML2.XMLHTTP60
http.Open "POST", "http://10.5.72.172:108/api/vbaemail", True
http.SetRequestHeader "Content-type", "application/json"
Call http.send("abc")
End Sub
Here's my simple web api.
public void Post([FromBody] string strJson)
{
SqlConnection cnnCom = null;
SqlCommand cmdCom = null;
string strSql = null;
//write parameter to table
cnnCom = new SqlConnection(CF.Get_Connection_String(CF.DatabaseName.COMMON));
cnnCom.Open();
strSql =
"INSERT INTO Test( " +
"F1) " +
"VALUES( " +
"'" + strJson + "')";
cmdCom = new SqlCommand(strSql, cnnCom);
cmdCom.ExecuteNonQuery();
cnnCom.Dispose();
}
Here is the working c# call to the web api:
static void Main(string[] args)
{
HttpClient hc = new HttpClient();
Task<HttpResponseMessage> task1 = null;
//call web api
task1 = hc.PostAsJsonAsync<string>
("http://10.5.72.172:108/api/vbaemail", "abc");
}