介紹:
我碰到了設計墻,遇到了一個我無法解決的問題。我可以使用指導。
我正在創建一個應用程式,我想url protocols用于可訪問性/安全性和用戶便利性。直到我準備好構建一個API. 到目前為止,我已經將我想要的功能編碼到我的應用程式中,包括下載方法和標準url protocool程式。
問題:
我使用的所有下載地址都WebUtility.UrlDecode()經過編碼,決議后需要提取可用的下載地址。問題是:如何存盤左鍵單擊生成的地址并將其傳遞給我的file downloader方法?我對如何完成這項任務感到困惑。重申:我想url protocol通過左鍵單擊捕獲我在線托管的一部分并將其存盤在一個變數中以供使用。
程式應該如何運行:
注意:?? = 作業。? = 不作業。
- 未知用戶在“頁面”上,并提供了一個選擇
Download & Install via through App?? - 用戶左鍵單擊超鏈接。??
- 下載地址資訊被傳遞給應用程式。?
- 應用程式打開。??
- 下載“x-item”的啟動并安裝(僅在我手動插入鏈接時有效)。??
實用地址示例:
<a href="myApp://httpsJ.amazon.8943fj9f8j3/test.json" target="_blank">Download & Install via myApp</a>
我想存...
https%4A%7F%0B.amazon.8943fj9f8j3%2Ftest.json //store this.
//and it would be decoded and made into a usable address to download from...
Example code...
//output desired from the original url.
string arg = "httpsJ.amazon.8943fj9f8j3/test.json ";
string encoded_url = arg.Trim().Split('/').Last();
string url = Uri.UnescapeDataString(enc_url);
//output example --> https://www.example.com/yadayada/sample.json
TLDR:為了簡單明了......在我看來,該應用程式的作業方式類似于用戶加入不和諧服務器的方式。用戶將單擊不和諧服務器邀請超鏈接,然后不和諧應用程式將打開并顯示提示訊息,詢問...用戶是否想加入服務器。
基本代碼。
static void Main()
//TESTING...START
string[] args = Environment.GetCommandLineArgs();
//args[0] is always the path to the application
RegisterMyAppProtocol(args[0]);
//the above method posted before, that edits registry
try
{
Console.WriteLine("Argument: " args[1].Replace("myapp:", string.Empty));
}
catch
{
Console.WriteLine("No argument(s)"); //if there's an exception, there's no argument
}
Console.ReadLine();
//TESTING...END
}
static void RegisterMyAppProtocol(string AppPath) //myAppPath = full path to application
{
//open myApp protocol's subkey
RegistryKey key = Registry.ClassesRoot.OpenSubKey("myApp");
//if the protocol is not registered yet...register it
if (key == null)
{
key = Registry.ClassesRoot.CreateSubKey("myApp");
key.SetValue(string.Empty, "URL: myApp Protocol");
key.SetValue("URL Protocol", string.Empty);
key = key.CreateSubKey(@"shell\open\command");
key.SetValue(string.Empty, AppPath.Replace("dll", "exe") " " "%1");
//%1 represents the argument - this tells windows to open this program with an argument / parameter
}
key.Close();
}
uj5u.com熱心網友回復:
我鏈接了多個論點,并能夠解決我的問題。結果是rawUrl/decodedUrl變數從按下協議 url 超鏈接回傳為所需的字串。
var rawUrl = string.Empty;
var decodedUrl = string.Empty;
try
{
//if there's an argument passed, write it
rawUrl = args[0];
if (rawUrl[rawUrl.Length - 1] == '/')
rawUrl = rawUrl.Remove(rawUrl.Length - 1);
Console.WriteLine($"Argument: {rawUrl}");
decodedUrl = returnURL(rawUrl);
}
catch
{
Console.WriteLine("No argument(s)"); //if there's an exception, there's no argument
}
if (!string.IsNullOrEmpty(decodedUrl))
{
//input method details so it does stuff.
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/436206.html
