In the beginning, I created several users in nextcloud. I have a microservice written in .NET, which sends PROPFIND requests to the nextcloud api depending on the user. I’m doing authorization for each user via a token.
For some reason, the api sometimes returns me an empty list instead of the contents of the repository. I thought there might be a problem with the Cookie files, but I still haven’t found a solution.
What could be the cause of my problem?
You’re going to have to give us more to go on.
Perhaps provide an example that uses curl
.
here is my method for sending the request
public async Task<DtoFilesInfoList?> GetNextcloudDirAsync(string filePath, DtoNextcloudAuthorizationResponse dtoNextcloudAuthorizationResponse)
{
string url = "/remote.php/dav/files/";
string xmlData = @"<?xml version=""1.0"" encoding=""utf-8""?>
<d:propfind
xmlns:d=""DAV:""
xmlns:oc=""http://owncloud.org/ns""
xmlns:ocs=""http://open-collaboration-services.org/ns""
xmlns:nc=""http://nextcloud.org/ns"">
<d:prop>
<d:displayname />
<d:getlastmodified />
<d:getcontentlength />
<d:getcontenttype />
<oc:id />
<oc:permissions />
<oc:owner-id />
<ocs:share-permissions />
<nc:sharees />
</d:prop>
</d:propfind>";
using var request = new HttpRequestMessage(
new HttpMethod(HttpMethodPropfind),
$"{url}{dtoNextcloudAuthorizationResponse.NextcloudLogin}/{Uri.UnescapeDataString(filePath)}"
);
request.Headers.Remove("Authorization");
request.Headers.Add("Authorization", "Bearer " + dtoNextcloudAuthorizationResponse.NextcloudToken);
request.Headers.Add("ocs-apirequest", "true");
var content = new StringContent(xmlData, Encoding.UTF8, "application/xml");
request.Content = content;
var response = await _httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
var xmlResponse = await response.Content.ReadAsStringAsync();
var jsonResponse = XmlHelper.ConvertXmlToJson(xmlResponse);
var filesList = JsonFormatHelper.FormatJsonNextcloudFiles(jsonResponse, dtoNextcloudAuthorizationResponse.NextcloudLogin);
return filesList;
}
if you need anything else, please write