Login response header, Sample login request (java) – Brocade Network Advisor REST API Guide (Supporting Network Advisor 12.3.0) User Manual
Page 36

22
Brocade Network Advisor REST API Guide
53-1003160-01
Logging in and out
3
The following are the header names and values. The password must be passed in as clear text.
Login response header
Upon successful authentication, a new client session is created and a token is returned through
the HTTP response header. The token identifies the client’s Network Advisor session and must be
used for all subsequent web service requests. The token expires after 10 minutes of no activity.
For information about the login response schema, refer to
Sample login request (Java)
The following is sample Java code for establishing a REST API session with Network Advisor. For a
Python example, see
“Creating a sample Python client.”
HttpURLConnection con = null;
try {
/**
* Create the HTTP connection object with the URI, method and headers
*/
URL obj = new URL("http://10.24.48.103/rest/login");
con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.addRequestProperty("WSusername", "Administrator");
con.addRequestProperty("WSpassword", "password");
con.addRequestProperty("Accept",
"application/vnd.brocade.networkadvisor+json;version=v1");
System.out.println("CALLING POST http://10.24.48.103/rest/login");
/**
* Make the HTTP call
*/
int responseCode = con.getResponseCode();
System.out.println("Response code is " + responseCode);
if (HttpURLConnection.HTTP_OK != responseCode) {
PRINT_ERROR(con);
assert false : "REST FAILED for login, responseCode = " + responseCode;
}
String token = con.getHeaderField("WStoken");
if (null != token) {
System.out.println("GOT TOKEN FROM RS RESPONSE = " + token);
PRINT_RESPONSE(con);
TABLE 5
Login request headers
Request header name
Request header value
Accept
The content type
WSusername
The valid Network Advisor user name
WSpassword
The password
TABLE 6
Login response header
Response header name
Request header value
WStoken
The token