Hello, I need to log in on the site using the API and get the token .

Request

 POST /api/2.0/authentication.json HTTP/1.1 Host: portal.onlyoffice.com Accept: application/json,application/xml Accept-Encoding: gzip, deflate userName=yourusername&password=yourpassword 

Response

 HTTP/1.1 200 Ok Cache-Control: private Content-Type: application/json; charset=utf-8 { "count": 0, "startIndex": 0, "status": 0, "response": { "token": "sdjhfskjdhkqy739459234", "expires": "2013-01-13T16:35:42.7564317+04:00" } } 

I wrote this code:

 private async Task<string> Authorize(string userName, string password) { var uri = new Uri("http://portal.onlyoffice.com/api/2.0/authentication"); var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("userName", userName), new KeyValuePair<string, string>("password", password) }); var client = new HttpClient(); var response = await client.PostAsync(uri.ToString(), formContent); var responseContent = await response.Content.ReadAsStringAsync(); dynamic jsonResult = JObject.Parse(responseContent); return jsonResult.token; } public async Task<ActionResult> LoginInExternal() { var token = await Authorize("email@gmail.com", "password"); return View(); } 

The problem is that after execution the server gives the answer:

{StatusCode: 402, ReasonPhrase: 'Server error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers}

What is the error and what possible solutions exist?

  • In this edition, your message does not contain a question, but contains a statement of the problem. Specify your problem. To do this, try to solve the problem yourself. Begin, for example, with the study of the class HttpClient - Dmitry
  • I also recommend that you read the help page. What questions are better not to ask? and with the topic How to answer questions about “homework”? - Dmitry
  • /api/2.0/authentication.json and /api/2.0/authentication are different urls . - aleksandr barakin

0