java - how to add header information in ODataConsumer in odata4j? -


i using code utilizes odata4j odataclientrequest , odataconsumer attempt call odata service requires authentication:

    string url = "https://mylocalhost/api/odata/people()?$filter=pid%20eq%20'10'";      map<string, string> headers = new hashmap<string, string>();     headers.put("accountid", "100");     odataclientrequest clientrequest = new odataclientrequest("get", url, headers, null, null);      odataconsumer consumer = odataconsumer.create(url);      for(oentity entity : consumer.getentities("people").execute()){ 

however, i'm getting authentication error, because server requesting header authentication information. how can create odataconsumer includes required authorization header information?

instead of manually adding header, believe can use basic authentication (since received authentication error) on client , can add built-in client "behavior" when set consumer. code basicauthenticationbehavior.java displayed in follwing link:

basicauthenticationbehavior.java

the code adding basic authentication behavior odataconsumer similar following:

odataconsumer.builder builder = odataconsumers.newbuilder(url); builder.setclientbehaviors(new basicauthenticationbehavior(loginusername, loginpassword));       odataconsumer c = builder.build();  for(oentity entity : c.getentities("entityname").execute()){     system.out.println(entity.getproperty("name").getvalue().tostring()); } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -