XMLHttpRequest();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2016 01:15 AM
Hi Team ,
Can you please guide me how to call
| var client=new XMLHttpRequest(); |
from Script Include, i have few parameters to be added to api call, so i cant use Rest Outbound here,
please suggest me
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2016 05:14 AM
Hi Ravi,
If this is a URL api then you can try below code in background script
var httpclient = Packages.org.apache.commons.httpclient;
var HttpClient = httpclient.HttpClient;
var UsernamePasswordCredentials = httpclient.UsernamePasswordCredentials;
var AuthScope = httpclient.auth.AuthScope;
var PostMethod = httpclient.methods.PostMethod;
// consider end point url as http://example.com/p.php
var client = new HttpClient();
var postMethod = postMethod = new PostMethod('endpoint url');
postMethod.addParameter("A", "Test");
postMethod.addParameter("B", "Test1");
postMethod.addParameter("C", "Test User8");
postMethod.addParameter("D", "TestUser8@example.com");
// these parameters will be replaced in the URL as below
http://example.com/p.php?A=Test&B=Test1&C=Test User8&D=TestUser8@example.com
var status = client.executeMethod( postMethod );
var result = (status + "\n" + postMethod.getResponseBodyAsString()).replace(/</g, "&"+"lt;");
gs.print(result);
postMethod.releaseConnection();
Mark my reply as Correct and also hit Like and Helpful if you find my response worthy.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
