Creating a Session using C# HttpClient
I am trying to create a session using c# code and am getting the weirdest error while creating a session (Note it does work through postman)
{"exception_body":{"http_response_code":401, "message":"No session exists.", "debug_message":"No session exists.","error_code":1000}}
Which is odd because I know the session does not exist I am trying to create it
Here is my c# code
using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Host = "dev.XXXX.cloud.opentext.com"; client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest"); var formConent = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("username", userName), new KeyValuePair<string, string>("password", password), }); HttpResponseMessage response; ApiResponse apiResponse = new ApiResponse(); try { response = await client.PostAsync("/otmmapi/v5/sessions", formConent); var responseJson = await response.Content.ReadAsStringAsync(); ....
I have tried with and without the Host, X-Requested-With and Accept Headers
Also I always get the same response whether or not the username and password is correct
It is returning the same error code as a GET but I confirmed it is actually doing a post
{Method: POST, RequestUri: 'https://dev.****.cloud.opentext.com/otmmapi/v5/sessions', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers: { Accept: application/json X-Requested-With: XMLHttpRequest Content-Type: application/x-www-form-urlencoded Content-Length: 49 }}
It does not work using the javascript sample code, I get a Xorigin error when trying to run the same code
jQuery.ajax({ url : "https://dev.XXXX.cloud.opentext.com/otmmapi/v5/sessions", method: "POST", data: {"username" : "", "password" : ""}}) .done(function() { console.log("dfsaf") }) .fail(function(req, res, data) {console.log(req, res, data)})
Comments
-
I think you are asking an Artesia(DAM/OTMM) question in the CS API forum
0 -
Thanks @Appu Nair
@Mike Bova , I moved your post.
I am trying to create a session using c# code and am getting the weirdest error while creating a session (Note it does work through postman)
{"exception_body":{"http_response_code":401, "message":"No session exists.", "debug_message":"No session exists.","error_code":1000}}
Media Management APIs
0 -
@Mike Bova Quick glance off the top of my head, perhaps its missing the JSESSIONID in the cookie.
Jeremy Naylor
Lead Quality Analyst | Engineering / XECM1
Categories
- All Categories
- 117 Developer Announcements
- 52 Articles
- 145 General Questions
- 132 Services
- 56 OpenText Hackathon
- 35 Developer Tools
- 20.6K Analytics
- 4.2K AppWorks
- 8.9K Extended ECM
- 912 Cloud Fax and Notifications
- 81 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 162 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 4 XM Fax