sriram_sig
5 years agoContributor
Solved
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
aq...
- 5 years ago
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 = "http://my.authenticatedService.com"; 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
Cheers
Lino