Hi.
After having some luck with curl using something like this:
curl -X GET -v http://localhost:16680/oemanager/applications/ -u tomcat:tomcat
..I am now trying to get this same information from the tomcat server in PASOE using .Net. Unfortunately, I am unable to get past the 401 Unauthorized error.
Am I way off base?
webClient = NEW WebClient(). myUri = NEW Uri("http://wintest"). netCred = NEW NetworkCredential("tomcat", "tomcat"). credCache = NEW CredentialCache(). credCache:Add(myUri, "Basic", netCred). webClient:Credentials = credCache. ASSIGN cURI = "wintest:8810/.../applications" lcString = webClient:DownloadString (cURI). webClient:Dispose() .
Migrated the above to 4GL ... mistook the request and the answer I provided was in C# (oops). OE did not like the casting of the repose to HttpWebResponse ... but removing that seemed to work.
USING System.IO.*.
USING System.Net.*.
define variable req as System.Net.WebRequest no-undo.
define variable resp as System.Net.WebResponse no-undo.
define variable dataStream as System.IO.Stream no-undo.
define variable reader as System.IO.StreamReader no-undo.
define variable json as character no-undo.
req = WebRequest:Create("revdevelev:7060/.../applications").
req:Credentials = new NetworkCredential("tomcat","tomcat").
req:Method = "GET".
resp = req:GetResponse().
dataStream = resp:GetResponseStream().
reader = new StreamReader(dataStream).
json = reader:ReadToEnd().
Can you please look at fiddler or any proxy to see what has been sent from the client ?
Jeff,
This works for me
WebRequest req = WebRequest.Create("server:7060/.../applications");
req.Credentials = new NetworkCredential("tomcat","tomcat");
req.Method = "GET";
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream dataStream = resp.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
String json = reader.ReadToEnd();
Console.WriteLine(json);
I've never used the CredentialCache ... leaving it out and trying webClient:Credentials = netCred might work?
Mark
Migrated the above to 4GL ... mistook the request and the answer I provided was in C# (oops). OE did not like the casting of the repose to HttpWebResponse ... but removing that seemed to work.
USING System.IO.*.
USING System.Net.*.
define variable req as System.Net.WebRequest no-undo.
define variable resp as System.Net.WebResponse no-undo.
define variable dataStream as System.IO.Stream no-undo.
define variable reader as System.IO.StreamReader no-undo.
define variable json as character no-undo.
req = WebRequest:Create("revdevelev:7060/.../applications").
req:Credentials = new NetworkCredential("tomcat","tomcat").
req:Method = "GET".
resp = req:GetResponse().
dataStream = resp:GetResponseStream().
reader = new StreamReader(dataStream).
json = reader:ReadToEnd().
Irfan, I've not used Fiddler before. I will take a look at it. It will be educational.
Mark, what you sent along appears to work. Thank you. I see that you are using WebRequest while I was using WebClient. Do you know if it's possible to use WebClient and achieve a successful result?
Jeff,
You can also use ABL for this.
There are some samples on GitHub, specifically https://github.com/PeterJudge-PSC/http_samples/blob/master/http_client/pasoe_rest_api/get_applications.p
/*------------------------------------------------------------------------ File : get_applications.p Purpose : Returns the list of applications from a PASOE server Author(s) : pjudge Created : Thu Oct 13 09:17:32 EDT 2016 Notes : * this is the equivalent of curl -X GET -v localhost:16680/.../ -u tomcat:tomcat ----------------------------------------------------------------------*/ block-level on error undo, throw. using OpenEdge.Net.HTTP.ClientBuilder. using OpenEdge.Net.HTTP.Credentials. using OpenEdge.Net.HTTP.IHttpClient. using OpenEdge.Net.HTTP.IHttpRequest. using OpenEdge.Net.HTTP.RequestBuilder. using OpenEdge.Net.URI. using OpenEdge.Net.HTTP.IHttpResponse. using Progress.Json.ObjectModel.JsonObject. /* *************************** Session config *************************** */ /* OPTIONAL FOR DEBUG/TRACING session:error-stack-trace = true. log-manager:logging-level = 6. log-manager:logfile-name = session:temp-dir + 'get_applications.log'. log-manager:clear-log(). */ /* *************************** Main Block *************************** */ define variable oClient as IHttpClient no-undo. define variable oUri as URI no-undo. define variable oReq as IHttpRequest no-undo. define variable oResp as IHttpResponse no-undo. define variable oCreds as Credentials no-undo. define variable oJson as JsonObject no-undo. oClient = ClientBuilder:Build():Client. oCreds = new Credentials('', 'tomcat', 'tomcat'). oUri = new URI('http', 'localhost', 16680). oUri:Path = '/oemanager/applications/'. oReq = RequestBuilder:Get(oUri) :UsingCredentials(oCreds) :Request. oResp = oClient:Execute(oReq). if type-of(oResp:Entity, JsonObject) then assign oJson = cast(oResp:Entity, JsonObject). /* do what you need to with the JSON here */ catch oError as Progress.Lang.Error : message oError:GetMessage(1) skip(2) oError:CallStack view-as alert-box. end catch.
Thanks Peter. I was just perusing the docs for this class(es). This example will be quite helpful.
Jeff,
WebcClient does work for me too.
webClient = NEW WebClient().
netCred = NEW NetworkCredential("tomcat", "tomcat").
webClient:Credentials = netCred.
ASSIGN lcString = webClient:DownloadString ("server:7060/.../applications").
webClient:Dispose() .
message lcString view-as alert-box.
Mark
Thanks Mark. That works as well. I suppose I was making it too complicated, but I was trying to follow the pattern found on MSDN. :)