-2

I am trying to direct download some files using basic authentication from 1fichier.com, this works perfectly in browsers "https://email:password@1fichier.com/?file_ID&auth=1", but i am trying to do the same thing in my application and nothing is working... i tried request header with pure email and password, i tried header with base64 encoded email and password , i tried to send a Post request with my credentials but i always get 401 error : Unauthorized. Does Anyone Know how can i send authentication in my http request to 1fichier servers ?

This is what they provided in their Help page :

After login, a Premium member can download unlimited number of files, without limitations. !!! You MUST login to be recognized as Premium !!!

You can also direct download using "basic authentication" : https://email:password@1fichier.com/?file_ID Tip: add &auth=1 to the URL. The server will ask for an authentication. '@' of the email address is invalid with this protocol and you must use '%' instead.

Wget example : wget 'download link' --no-check-certificate --http-user='email' --http-password='password' --auth-no-challenge --content-disposition

     using UnityEngine.Networking;

     string user = "my email";
     string password = "my password";
     string combined = user + ":" + password;
     
     UnityWebRequest request = UnityWebRequest.Get("https://1fichier.com/?cs6czd22c8odod74dal2&auth=1");
     request.SetRequestHeader("Authorization","Basic " + combined);
     yield return request.SendWebRequest();
     if(request.isHttpError)
     {
       Debug.Log(request.error);
     }
      else
     {
         if (request.isDone)
         {
             Debug.Log("Done");
         }
     }

The base64 encoded :

     using UnityEngine.Networking;

     string user = "my email";
     string password = "my password";
     string base64User = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(user));
     string base64pass = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(password));
     string combined = base64User + ":" + base64pass;
     UnityWebRequest request = UnityWebRequest.Get("https://1fichier.com/?cs6czd22c8odod74dal2&auth=1");
     request.SetRequestHeader("Authorization","Basic " + combined);
     yield return request.SendWebRequest();
     if(request.isHttpError)
     {
         Debug.Log(request.error);
     }
     else
     {
         if (request.isDone)
         {
             Debug.Log("Done");
         }
     }
CS_Studios
  • 21
  • 3
  • Show us the code you've tried – Martheen Apr 30 '21 at 07:49
  • Because of the lack of code, hard to tell if this is related or duplicated of other questions like [this one](https://stackoverflow.com/questions/4334521/httpwebrequest-using-basic-authentication) – Cleptus Apr 30 '21 at 07:51
  • look into their api documentation. 401 is an authorization issue and this should be covered by their docs. – jegtugado Apr 30 '21 at 07:58
  • welcome to stackoverflow. i recommend [taking the tour](https://stackoverflow.com/tour), as well as reading [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and [what's on topic](https://stackoverflow.com/help/on-topic). as a first pointer: if you want help ***debugging your code*** - how do you think this to be possible without you ***showing us your code***? – Franz Gleichmann Apr 30 '21 at 08:01
  • Are you using HTTP or HTTPS? Https uses TLS for authentication. You are getting an authentication error due to TLS failing or not using HTTPS which is more likely. – jdweng Apr 30 '21 at 08:19

1 Answers1

1

I Found What i am looking for, it didn't have anything to do with the request header;

the original url that i pasted in the browser is like this : "https://myemail@gmail.com:mypassword@1fichier.com/?File_ID&auth=1";

so i recorder the browser's web request and the url came out like this : "https://myemail%40gmail.com:mypassword@1fichier.com/?File_ID&auth=1";

i pasted this in my application in the get request as a url and it worked perfecly.

using UnityEngine.Networking;
UnityWebRequest request = UnityWebRequest.Get("https://myemail%40gmail.com:mypassword@1fichier.com/?File_ID&auth=1");
CS_Studios
  • 21
  • 3