Highlighted
Absent Member.
Absent Member.
467 views

urlPost() implementation ECMA ?


NetiQ IDM 4.0.2 AE


Hello can someone provide me the implementation of how to post some xml
content (body) to a external webservice using standard ECMA script?

I found urlGet() implementation on this forum, Anyone can help me out
with urPost() implementation?


function urlGet(urlString) {



try {
var url = new java.net.URL(String(urlString));
var connection = url.openConnection();

connection.setRequestProperty("Authorization", "Basic " +
"SWRlbnRpdHlNZ210OjZDamRjM1dk");
connection.connect();
var stream = connection.getInputStream();

var reader = new java.io.InputStreamReader(stream);
var sb = new java.lang.StringBuilder();
var c;

while ((c = reader.read()) != -1) {
sb.append(String.fromCharCode(c));
}
return sb.toString();
} catch(e) {
return e.toString();
}
}


--
belaie
------------------------------------------------------------------------
belaie's Profile: https://forums.netiq.com/member.php?userid=308
View this thread: https://forums.netiq.com/showthread.php?t=53113

Labels (1)
0 Likes
3 Replies
Highlighted
Absent Member.
Absent Member.

Re: urlPost() implementation ECMA ?


belaie;255317 Wrote:
> NetiQ IDM 4.0.2 AE
>
>
> Hello can someone provide me the implementation of how to post some xml
> content (body) to a external webservice using standard ECMA script?
>
> I found urlGet() implementation on this forum, Anyone can help me out
> with urPost() implementation?
>
>
> function urlGet(urlString) {
>
>
>
> try {
> var url = new java.net.URL(String(urlString));
> var connection = url.openConnection();
>
> connection.setRequestProperty("Authorization", "Basic " +
> "SWRlbnRpdHlNZ210OjZDamRjM1dk");
> connection.connect();
> var stream = connection.getInputStream();
>
> var reader = new java.io.InputStreamReader(stream);
> var sb = new java.lang.StringBuilder();
> var c;
>
> while ((c = reader.read()) != -1) {
> sb.append(String.fromCharCode(c));
> }
> return sb.toString();
> } catch(e) {
> return e.toString();
> }
> }


Unconfirmed example of *urlPost* Ecma function published by Peter
Lambrechtsen in comment section on Robert Rivey blog
http://blog.robertivey.org/2010/04/web-services-with-novell-idm.html

> importClass(java.net.URL);
> importClass(java.net.Proxy);
> importClass(java.net.HttpURLConnection);
> importClass(java.net.InetSocketAddress);
> importClass(java.io.InputStreamReader);
> importClass(java.io.OutputStream);
> importClass(java.io.OutputStreamWriter);
> importClass(java.io.PrintStream);
> importClass(java.lang.StringBuilder);
>
> function urlPost(urlString,inputvar) {
> try {
> var url = new java.net.URL(String(urlString));
> var test = urlString;
>
> // If you need a Proxy Server to send your HTTP Request
> // var addr = new InetSocketAddress("127.0.0.1", 8080);
> // var proxy = new Proxy(Proxy.Type.HTTP, addr);
> // var conn = url.openConnection(proxy);
> // Or Direct
> var conn = url.openConnection();
>
> conn.setDoOutput(true);
> conn.setRequestMethod("POST");
> conn.setRequestProperty("Content-Type", "text/xml");
> var osw = new OutputStreamWriter(conn.getOutputStream());
> osw.write(inputvar);
> osw.flush();
> var reader = new java.io.InputStreamReader(conn.getInputStream(),
> "UTF-8");
> var sb = new java.lang.StringBuilder();
> var c;
> while ((c = reader.read()) != -1) {
> sb.append(String.fromCharCode(c));
> }
> return sb.toString();
> } catch(e) {
> return e.toString();
> }
> }



--
al_b
------------------------------------------------------------------------
al_b's Profile: https://forums.netiq.com/member.php?userid=209
View this thread: https://forums.netiq.com/showthread.php?t=53113

0 Likes
Highlighted
Absent Member.
Absent Member.

Re: urlPost() implementation ECMA ?


Hello

I actually found that but it did not work for me. I have googled a lot,
and one thing I can see that if you want to send xml content to a
webservice using POST, in java it should be like this;
http://tinyurl.com/m367b23

but i'm not sure how to convert the 3rd line in ECMAScript ( type
casting); it looks like that URLConnection should be converted to the
HttpURLConnection.


URL urlForInfWebSvc = new URL(urlString);
URLConnection UrlConnInfWebSvc =
urlForInfWebSvc.openConnection();
HttpURLConnection httpUrlConnInfWebSvc = (HttpURLConnection)
UrlConnInfWebSvc;





al_b;255319 Wrote:
> Unconfirmed example of *urlPost* Ecma function published by Peter
> Lambrechtsen in comment section on Robert Rivey blog
> http://blog.robertivey.org/2010/04/web-services-with-novell-idm.html



--
belaie
------------------------------------------------------------------------
belaie's Profile: https://forums.netiq.com/member.php?userid=308
View this thread: https://forums.netiq.com/showthread.php?t=53113

0 Likes
Highlighted
Absent Member.
Absent Member.

Re: urlPost() implementation ECMA ?


Just updating the issue here. it was actually working, the webservice
which I was trying with required some HTTP headers which I did not have
at first place. Thank your for the info.


--
belaie
------------------------------------------------------------------------
belaie's Profile: https://forums.netiq.com/member.php?userid=308
View this thread: https://forums.netiq.com/showthread.php?t=53113

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.