I tried to send a HttpRest Call using NTLM Autentication in Java. I tried using the org.apache.http library. it was not a big problem to use the HttpClient to send a Post Request with anonymos authentication.
But i have some troubles with WindowsAuthentication. I even tried to use CredentialProvider with my own Windows credentials (as a compromise, i dont like that either) but i didn’t succeed.
Is there an easy way using NTLM Authentication sending post requests from Java code?
Is there another lib which fits better form my needs?
I still have no idea why the doku from https://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html about NTLM Authentication didn’t have worked for me.
I finally solved my problem doing it similar to the documentation for basic authentication as described on http://www.baeldung.com/httpclient-post-http-request
it now looks like this:
...
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
new NTCredentials("username", "passwd", hostname, "domain.at"));
HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
HttpPost post = new HttpPost("http://www.example.com"));
StringEntity input = new StringEntity(bodyAsString, HTTP.UTF_8);
input.setContentType("application/json");
input.setContentEncoding("UTF-8");
post.setEntity(input);
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(post);
...
Related
I am just trying to authenticate from NetSuite to docusign. I have my demo account, and am able to send requests successfully using the legacy authentication from postman.
However, when I try the same code in a server side situation, i get the INVALID_TOKEN_FORMAT error.
I've only built 3 or 4 apis so would really appreciate what I might be missing that's causing this 401 error.
NetSuite code (js syntax):
headers = {
'Accept':'application/json',
'Content-Type':'application/json',
'X-DocuSign-Authentication':{'Username':'abcusername','Password':'password123','IntegratorKey':'xyz123'}
};
res = nlapiRequestURL('https://demo.docusign.net/restapi/v2/login_information', '', headers, 'GET');
Ok solved! The authentication object needed to be in xml. Confused bc of the content type and the documentation shows JSON
I'm trying to do a POST request from any of rest client like (Advanced rest client, Postman etc) for posting a request with mime type "multipart/related" but none of rest client supports. So is there a way to quickly POST a request from any of rest clients or other alternate solutions?
Though I have not tried multipart/related, but multipart/mixed using jersey client.
Using Jersey client
Create a multipart request .. eg.
MultiPart multiPart = new MultiPart();
multiPart.bodyPart(....//
Then call the service like :
Client c = Client.create();
WebResource service = c.resource(Url);
ClientResponse response = service.type("multipart/mixed").header(headerkey,
headervalue).post(ClientResponse.class, multiPart);
Similarly try it for multipart/related.
you have download jersery client jar from https://jersey.java.net/download.html
Attached image will help you, This way you can try using Advance Rest Client plugin in Chrome, and also don't forget to upload the file under the Files tab.
I am trying to hit the alfresco rest api using my standalone rest code. i get the login ticket when i use the below url -
"http://host:port/alfresco/service/api/login?u=admin&pw=admin"
and i got the ticket but how do i use this ticket for further communication with alfresco without facing this authentication problem.
below is the code i am using for communicating with the alfresco rest client.
HttpGet getReq = new HttpGet(url);
getReq.addHeader("accept", "application/json");
StringEntity input = new StringEntity(args);
HttpResponse response = client.execute(getReq);
Kind Regards
Garvit Jain
Append the alf_ticket argument to your URL and pass in the ticket you retrieved from the /api/login call. See http://wiki.alfresco.com/wiki/Web_Scripts#Authenticating
i m using GWT 2.2 and restlet-gwt-2.1m4.
i m trying to call a rest service that uses HTTP Digest.
So i used the tutorial on Restlet wiki :
http://wiki.restlet.org/docs_2.1/13-restlet/27-restlet/46-restlet/112-restlet.html
First thing is this does not compile :
ChallengeResponse challengeResponse = new ChallengeResponse(c1,
resource.getRequest(),
resource.getResponse(),
"login",
"secret".toCharArray());
So i changed it to
// 2- Create the Challenge response used by the client to authenticate its requests.
ChallengeResponse challengeResponse = new ChallengeResponse(ChallengeScheme.HTTP_DIGEST,
"login",
"secret");
My second problem, is that no request are sent.
I checked with Firebug and there is nothing (no GET request).
It seems that resource.get(); isnt sending anything at all.
Any idea what i am missing ? Does the code in the tutorial actually work ?
Thanks in advance
How can I had soap AUTH BASIC auth to a WSDL, so who ever reads the WSDL knows I require that operation for a specific method ?
Using the example bellow I have managed to pass the SOAP basic autentication to the php webservice on the other end.
The PHP.net/Soapclient has a simple working example, but in csharp I found this link to be a solution to my problem.
link
Michaelis.MockService is the Webservice library extracted you may see an example on how to do this in:
link Mono project website.
Michaelis.MockService service = new Michaelis.MockService();
// Create the network credentials and assign
// them to the service credentials
NetworkCredential netCredential = new NetworkCredential(“Inigo.Montoya”, “Ykmfptd”);
Uri uri = new Uri(service.Url);
ICredentials credentials = netCredential.GetCredential(uri, “Basic”);
service.Credentials = credentials;
// Be sure to set PreAuthenticate to true or else
// authentication will not be sent.
service.PreAuthenticate = true;
// Make the web service call.
service.Method();
There is no way to specify this, as far as I know.