/********************************************************
Purpoese : Program to generate the token for HP VAN controller
Library : libcurl is used
Usage : gcc -o token hp_forum_token.c -lcurl
Reference Command :
curl -k -X POST "https://127.0.0.1:8443/sdn/v2.0/auth" -d '{"login":{"user":"sdn","password":"skyline"}}' -H "Content-Type:application/json"
*/
#include <stdio.h>
#include <curl/curl.h>
#include<string.h>
#include<stdlib.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
struct curl_slist *slist = NULL;
/* -H Header */
slist = curl_slist_append(slist, "Content-type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
/* URL */
curl_easy_setopt(curl, CURLOPT_URL, "https://127.0.0.1:8443/sdn/v2.0/auth");
/* -X POST */
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "user=sdn&password=skyline&domain=sdn");
/* -v option */
curl_easy_setopt(curl,CURLOPT_VERBOSE,1L);
/* -k option */
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_slist_free_all(slist);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}
Hi Team,
I installed the HP SDN VAN controller software. I can able to successfuly generate the token using the following curl command as mentioned in HP documentation.
"curl -k -X POST "https://127.0.0.1:8443/sdn/v2.0/auth" -d '{"login":{"user":"sdn","password":"skyline"}}' -H "Content-Type:application/json"
As a part of application development using HP SDN VAN Controller, I used libcurl library utility to generate the token. I am facing issues as I could not able to generate the token. I followed all the option setting as mentioned in above curl command. I am not sure whether any other options needs to given to generate the token. The following is the error generated.
Refer the code as shown above for reference. Any help is appreciated. Thanks for understanding
================ Error Message ============================
* About to connect() to 127.0.0.1 port 8443 (#0)
* Trying 127.0.0.1... * connected
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSL connection using DHE-DSS-AES256-SHA
* Server certificate:
* subject: C=CA; ST=CA; L=Palo Alto; O=HP; OU=HP SDN Controller; CN=127.0.1.1
* start date: 2014-04-15 14:22:31 GMT
* expire date: 2014-07-14 14:22:31 GMT
* issuer: C=CA; ST=CA; L=Palo Alto; O=HP; OU=HP SDN Controller; CN=127.0.1.1
* SSL certificate verify result: self signed certificate (18), continuing anyway.
> POST /sdn/v2.0/auth HTTP/1.1
Host: 127.0.0.1:8443
Accept: */*
Content-type: application/json
Content-Length: 36
* upload completely sent off: 36out of 36 bytes
< HTTP/1.1 400 Bad Request
< Server: Apache-Coyote/1.1
< X-FRAME-OPTIONS: deny
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, PUT, HEAD, PATCH
< Access-Control-Allow-Headers: Content-Type, Accept, X-Auth-Token
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Tue, 08 Jul 2014 20:00:50 GMT
< Connection: close
<
* Closing connection #0
{"error":"java.lang.IllegalArgumentException","message":"Unable to parse login data: Unexpected character ('u' (code 117)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: java.io.StringReader@34e34720; line: 1, column:
==================================================================================