Ergebnis 1 bis 1 von 1

Thema: [CODE][c#]simple API example

  1. #1
    Anfänger
    Registriert
    Apr 2017
    Beiträge
    2
    Gefällt mir!
    1
    Du gefällst: 3

    Post [CODE][c#]simple API example

    Thanks for Filecrypt.cc. Sorry i don't speak german.
    If it is not the right thread, please move it.

    This is not a fully, exhaustive, implementation of Filecrypt.cc API. Far from it.
    It's just a basic sample, but you can easily modify for your needs.
    The http is an asynchronous call.
    If you prefer JSON than XML, you can use JavaScriptSerializer().Deserialize.
    You can use this code without any restriction.
    Any comments are welcome.

    usage:
    Code:
    string lFilecrypt = string.Empty;
    using (filecrypt fc = new filecrypt())
       lFilecrypt = fc.clFilecrypt(params);
    PHP-Code:
    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Net;
    using System.Text;
    using System.Text.RegularExpressions;

    namespace 
    uploaderNet
    {
        
    internal class filecrypt IDisposable
        
    {
            public 
    void Dispose()
            {
                
    Dispose(true);
                
    GC.SuppressFinalize(this);
            }

            ~
    filecrypt()
            {
                
    Dispose(false);
            }

            protected 
    virtual void Dispose(bool disposing)
            {

            }

            public 
    filecrypt()
            {

            }

            private 
    void finishWReq(IAsyncResult wResHttpWebRequest wReqout string lFilecrypt)
            {
                
    string s string.Empty;
                
    lFilecrypt string.Empty;
                
    using (HttpWebResponse wr = (HttpWebResponse)wReq.EndGetResponse(wRes))
                    if (
    wr.StatusCode == HttpStatusCode.OK)
                        
    using (Stream st wr.GetResponseStream())
                            
    using (StreamReader sr = new StreamReader(st))
                                
    sr.ReadToEnd();

                if((
    s.ToLower().Contains("error")) || string.IsNullOrEmpty(s))
                    throw new 
    Exception("filecrypt.cc error");
                
    MatchCollection mc = new Regex(@"<container><link>(.*?)</link>"RegexOptions.IgnoreCase).Matches(s);
                if(
    mc.Count 0)
                    
    lFilecrypt mc[0].Groups[1].Value;
            }

            
    /// <summary>
            /// Create Link Filefrypt.cc from links.
            /// usage: string lFilecrypt = new filecrypt().clFilecrypt(params);
            /// Or
            /// string lFilecrypt = string.Empty;
            /// using (filecrypt fc = new filecrypt())
            ///     lFilecrypt = fc.clFilecrypt(params);
            /// more info:
            /// http://filecrypt.cc/api.pdf
            /// http://filecrypt.cc/docs/index.htm#api-containerV2-create
            /// </summary>
            /// <param name="idFilecrypt">your API key</param>
            /// <param name="title">foldername</param>
            /// <param name="links">links separated by \n</param>
            /// <returns>complete url to folder</returns>
            
    public string clFilecrypt(string idFilecryptstring titlestring links)
            {
                
    string s "fn=container&sub=create&fmt=xml&api_key=" idFilecrypt;
                
    += "&foldername=" title;
                
    //string s = "fn=containerV2&sub=create&fmt=xml&api_key=" + idFilecrypt;
                //s += "&name=" + title;
                //s += "&mirror_1=" + links;
                //s += "&group=group1";
                
    += "&mirror[]=" links;
                
    += "&captcha=0";
                
    += "&allow_cnl=1";
                
    += "&allow_dlc=1";
                
    += "&allow_links=0";

                
    HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(new Uri("https://www.filecrypt.cc/api.php"));

                
    wReq.Timeout 200000;
                
    wReq.Proxy.Credentials CredentialCache.DefaultCredentials;
                
    wReq.ContentType "application/x-www-form-urlencoded";
                
    wReq.Method "POST";
                
    //wReq.UserAgent = new util().UserAgent;
                
    wReq.Accept "*/*";
                
    byte[] Encoding.UTF8.GetBytes(s);
                
    wReq.ContentLength b.Length;
                
    string lFilecrypt string.Empty;
                try
                {
                    
    using (Stream dataStream wReq.GetRequestStream())
                        
    dataStream.Write(b0b.Length);
                    
    wReq.BeginGetResponse(wRes => { finishWReq(wReswReqout lFilecrypt); }, null);
                }
                catch (
    Exception ex)
                {  }
                if (
    string.IsNullOrEmpty(lFilecrypt))
                    throw new 
    Exception("filecrypt.cc error");
                return 
    lFilecrypt;
            }
        }


  2. Diesen Mitgliedern gefällt dieser Beitrag:


  3. Werbung - Hier werben?

Ähnliche Themen

  1. SSBG - Simple Szene BBcode Generator
    Von Uranjitsu im Forum Archiv
    Antworten: 25
    Letzter Beitrag: 08.07.2020, 16:41
  2. [Biete] Simple Googe Drive Manager for Windows
    Von maz im Forum Exploits, Codes & Tools
    Antworten: 20
    Letzter Beitrag: 27.07.2016, 18:57

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  
SzeneBox.org... im Mittelpunkt der Szene!
© since 2015 szeneBOX.org - All Rights Reserved
Domains: www.szenebox.org