0

I am using the below code to get a response from API, however, I am only getting a blank response. Can someone help here

Dim oDic As New Dictionary
Dim oRequest As New MSXML2.XMLHTTP
' Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")

oRequest.Open "POST", "https://neutrinoapi.com/phone-validate", True

oRequest.SetRequestHeader "user-id", "haissk"
oRequest.SetRequestHeader "api-key", "key"
oRequest.SetRequestHeader "number", "1234567890"

oRequest.Send 

While oRequest.readyState <> 4
    DoEvents
Wend

MsgBox oRequest.ResponseText

I've also tried

oRequest.Send EncodeBase64("user-id=haissk&api-key=key=1234567890")

When I try the same from C# it just works fine. Below is the C# code

using (var client = new HttpClient())
{
    var req = new List<KeyValuePair<string, string>>();
    req.Add(new KeyValuePair<string, string>("user-id", "haissk"));
    req.Add(new KeyValuePair<string, string>("api-key", "key"));
    req.Add(new KeyValuePair<string, string>("number", "1234567890"));

    var content = new FormUrlEncodedContent(req);
    var response = await client.PostAsync("https://neutrinoapi.com/phone-validate", content);
    var responseStr = await response.Content.ReadAsStringAsync();

    JObject result = JObject.Parse(responseStr);
}
GSerg
  • 76,472
  • 17
  • 159
  • 346
Sam K
  • 332
  • 1
  • 6
  • 19
  • 1
    Those two code samples don't do the same thing? The first one uses request headers and the second one sends the data in the request as the POST body. – Tim Williams Nov 07 '18 at 07:18
  • Try to remove all `.SetRequestHeader` from the VBA code and use `oRequest.Send "user-id=haissk&api-key=key&number=1234567890"`, don't forget to [URLEncode](https://stackoverflow.com/a/34601029/2165759) each values before concatenation. – omegastripes Nov 07 '18 at 08:11
  • Did you check the response status? Did you get a 403? – QHarr Nov 07 '18 at 08:36

0 Answers0