【问题标题】:HTTP basic authentication for 1fichier.com1fichier.com 的 HTTP 基本身份验证
【发布时间】:2021-04-30 07:46:55
【问题描述】:

我正在尝试使用 1fichier.com 的基本身份验证直接下载一些文件,这在浏览器“https://email:password@1fichier.com/?file_ID&auth=1”中完美运行,但我正在尝试执行我的应用程序中的相同内容并且没有任何工作...我尝试使用纯电子邮件和密码的请求标头,我尝试使用 base64 编码的电子邮件和密码的标头,我尝试使用我的凭据发送 Post 请求,但我总是收到 401 错误:未经授权.有人知道如何将我的 http 请求中的身份验证发送到 1fichier 服务器吗?

这是他们在帮助页面中提供的内容:

登录后,高级会员可以下载无限数量的文件,没有限制。 !!!您必须登录才能被识别为高级版!!!

您也可以使用“基本认证”直接下载: https://email:password@1fichier.com/?file_ID 提示:添加 &auth=1 到网址。服务器将要求进行身份验证。 电子邮件地址的“@”在此协议下无效,您必须改用“%”。

Wget 示例: wget '下载链接' --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");
         }
     }

base64 编码:

     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");
         }
     }

【问题讨论】:

  • 向我们展示您尝试过的代码
  • 由于缺少代码,很难判断这是否与this one等其他问题有关或重复
  • 查看他们的 api 文档。 401 是一个授权问题,这应该在他们的文档中涵盖。
  • 欢迎使用 stackoverflow。我推荐taking the tour,以及阅读how to ask a good questionwhat's on topic。作为第一个指针:如果您需要帮助调试您的代码 - 如果没有您向我们展示您的代码,您认为这如何成为可能>?
  • 您使用的是 HTTP 还是 HTTPS? Https 使用 TLS 进行身份验证。由于 TLS 失败或未使用 HTTPS 而这更有可能导致身份验证错误。

标签: c# unity3d authentication httprequest basic-authentication


【解决方案1】:

我找到了我要找的东西,它与请求标头没有任何关系;

我在浏览器中粘贴的原始网址是这样的: "https://myemail@gmail.com:mypassword@1fichier.com/?File_ID&auth=1";

所以我记录了浏览器的网络请求,并且 url 如下所示: "https://myemail%40gmail.com:mypassword@1fichier.com/?File_ID&auth=1";

我将它作为 url 粘贴到我的应用程序中的 get 请求中,它运行良好。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-21
    • 2011-11-12
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-19
    相关资源
    最近更新 更多