I know that my question is similar to other questions here, but I think I have a different scenario. I'm trying to upload some css files to sitecore (in my case Sc 9.0.1) by calling this url using
WebClient()
"/sitecore modules/PowerShell/Services/RemoteScriptCall.ashx?user=sitecore\******&password=*&script=\Themes\ExampleProject\ExampleProject Main Theme/styles&sc_database=master&apiVersion=media&scriptDb=master".
This is my code:
public string Upload(string filePath)
{
if (!Directory.Exists(Directory.GetParent(filePath).FullName))
return $"The file {filePath} could not be found";
using (var webClient = new WebClient())
{
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"username:password"));
webClient.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", credentials);
webClient.Headers.Add("user-agent", @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36");
webClient.Headers.Add("Accept", "*/*");
webClient.Credentials = new NetworkCredential("*****", "*", "sitecore");
byte[] responseArray = webClient.UploadFile(_targetUri, "POST", filePath);
return filePath;
}
}
As an answer from the server, I got, the error 403 (Forbidden) although I entered the admin credentials of the site.
Does someone know where the problem is?
Thanks