Ask a Question

How to create a GetRequest on a intranet application as a specific user using aqHttpRequest


How to create a GetRequest on a intranet application as a specific user using aqHttpRequest

I'm using the below code to post a GetRequest on a intranet site, but i'm getting a 401 unauthorized error and in the intranet application logs i dont see a user name listed on the get request

  aqHttpRequest = aqHttp.CreateGetRequest(address)

  # Send the request, get an aqHttpResponse object
  aqHttpResponse = aqHttpRequest.Send() 
  # Read the response data
  Log.Message(aqHttpResponse.AllHeaders) # All headers
  Log.Message(aqHttpResponse.GetHeader("Content-Type")) # A specific header
  Log.Message(aqHttpResponse.StatusCode) # A status code 
  Log.Message(aqHttpResponse.StatusText) # A status text
  Log.Message(aqHttpResponse.Text) # A response body
Community Hero

That is because you did not set the header before you made the request.

It is obvious that your httprequest requires authentication.  That means you have to use the aqHttpRequest object method called "SetHeader" to se the username and password before you call the request method.


function httpPostRequest()
  var address = "";
  var username = "Lino";
  var password = "passsword";
  // Define the request body JSON string
  var requestBody = '{ "id": 23, "category": { "id": 5, "name": "dogs"}, "name": "fido"}'; 
  // Create the aqHttpRequest object
  var aqHttpRequest = aqHttp.CreatePostRequest(address, username, password);

  // Specify the Content-Type header value
  aqHttpRequest.SetHeader("Content-Type", "application/json");

  // Send the request, create the aqHttpResponse object
  var aqHttpResponse = aqHttpRequest.Send(requestBody)

  // Check the response:
  Log.Message(aqHttpResponse.StatusCode); // A status code 
  Log.Message(aqHttpResponse.Text); // A body


Hope that makes sense



Showing results for 
Search instead for 
Did you mean: