Forum Discussion

Al2's avatar
Al2
Occasional Contributor
5 years ago

Bad request' error 400 in Testcomplete POST request

Hello,

 

I'm trying to send http POST request to a server to receive a JSON token.

I keep getting 'Bad Request' error. So far I have been unable to find out the real issue here.

There's not request payload required for this service call.  I've tried the same thing in postman/soapui, it  just works fine

 

If anyone can give me some direction here, I'd really appreciate it.

 

function httpPostRequest()
{
var address ="http://dc2-amopoclak.com:11114/services//auth"
var username = "ALPOLD"
var password = "XXXXXX"; 

  // Create the aqHttpRequest object
  var aqHttpRequest = aqHttp.CreatePostRequest(address, username, password);
  aqHttpRequest.SetHeader("Content-Type", "application/json");
  //There's not request payload for this
  var aqHttpResponse = aqHttpRequest.Send();
 if(aqHttpResponse.StatusCode == 200) { 
return true;
}else{ 
return false;
}

}

Thank you

Al

 

 

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Al2,

     

    Could you please review the aqHttp.CreatePostRequest Method  article? You may need to perform some additional steps depending on the auth type.

     

    BTW, why dodo you have a double slash in the URL?

    http://dc2-amopoclak.com:11114/services//auth
     

     

    • Al2's avatar
      Al2
      Occasional Contributor

      Thank you Tanya! I think I added a // by mistake while posting it here. I'm not using '//' in my code.

       

      I reread this article, and the only difference I noticed evertime, my program doesn't have a request body for API call. I don't need a request body to make this POST call.

       

      Thank you

      Al2 

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    > I've tried the same thing in postman/soapui, it  just works fine

    Use some recording proxy (e.g. Fiddler) to record requests sent by SoapUI and TestComplete. Compare recorded requests and make the one sent from TestComplete to match those sent from SoapUI.