08-08-2011 08:01 AM
Login (POST)
POST /alfresco/service/api/login
—
Login and establish a ticket.
Input
JSON Data Object.
username
cleartext username
password
cleartext password
Returns the new authentication ticket.
…
strUri = "http://localhost:8080/alfresco/service/api/login";
strJson = @"[""username"", ""admin"", ""password"", ""contacts""]";
// Create the Web Request Object
WebRequest request = WebRequest.Create(strUri);
// Specify that you want to POST data
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
if (strUri != null)
{
// write out the data to the web server
writeToURL(request, strJson);
}
else
{
request.ContentLength = 0;
}
// read the response from the Web Server
strHtmlContent = retrieveFromURL(request); //Das Lesen der Antwort ergibt einen Fehler
….
private String retrieveFromURL(WebRequest request)
{
// 1. Get the Web Response Object from the request
WebResponse response = request.GetResponse();
// 2. Get the Stream Object from the response
Stream responseStream = response.GetResponseStream();
// 3. Create a stream reader and associate it with the stream object
StreamReader reader = new StreamReader(responseStream);
// 4. read the entire stream
return reader.ReadToEnd();
}// end retrieveFromURL method
Leider gibt es hier immer den Fehler 404, 'Bad request' sobald ich versuche die Antwort zu lesen. Der Fehler tritt auf in der Funktion retrieveFromURL in der ersten Zeile.08-08-2011 08:59 AM
//anstatt strJson = @"[""username"", ""admin"", ""password"", ""contacts""]";
strJson = "{username: \"admin\", password: \"contact\"}"; //wenn contacts dein PW ist
//anstatt request.ContentType = "application/x-www-form-urlencoded";
request.ContentType = "application/json";
VG, Jan
08-08-2011 09:06 AM
curl http://localhost:8080/alfresco/service/api/login -H "content-type: application/json" -d "{username: \"admin\", password: \"contacts\"}"
–> sowas wie
{
"data":
{
"ticket":"TICKET_6c3ba5ca3b72872b7ddbe8bcde9cca86f36af08c"
}
}
08-09-2011 08:00 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.