VMware Cloud Community
mayank_goyal
Enthusiast
Enthusiast

vRO URL Class

I am trying to use the URL class to do a POST call. The problem is that it is executing but I couldn't get the response. Any ideas? I know this can be easily done via REST Class though but that's not the point.

mayank_goyal_0-1679405139089.png

 

var obj = new URL("http://vrops_fqdn/suite-api/api/auth/token/acquire");

//Option 1

// var content = {
//         "username" : "username@domain.local", 
//         "password" : "pa$$w0rd1"
// };

//obj.requestType = "POST";
//obj.contentType = "application/json";
//obj.postContent(content);

//Option 2
obj.addParameter("username","username@domain.local");
obj.addParameter("password","pa$$w0rd1");
obj.requestType = "POST";
obj.contentType = "application/json";
System.log(obj.post());
System.log(obj.result);

 

 



-
For more interesting content on Aria Automation, check my blog:
https://cloudblogger.co.in
0 Kudos
3 Replies
eoinbyrne
Expert
Expert

If you are trying to POST you probably need to set the body content for the request? The addParameter will add "&name=value" to the end of the URL. If your POST is supposed to contain content then you'll need to use either

- URL.datas = mycontent;

OR

- URL.postContent(mycontent);

 

 

0 Kudos
bdamian
Expert
Expert

I will suggest that you add the vROps as a Rest Host, then use Request classes to do the request

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
0 Kudos
mayank_goyal
Enthusiast
Enthusiast

i think i tried it as Option 1 (which is commented out).



-
For more interesting content on Aria Automation, check my blog:
https://cloudblogger.co.in
0 Kudos