MultipartFormDataPost() public static method

Post the data as a multipart form
public static MultipartFormDataPost ( string postUrl, string userAgent, Dictionary, values, string boundary ) : HttpWebResponse,
postUrl string
userAgent string
values Dictionary,
boundary string
return HttpWebResponse,
示例#1
0
        private ImageResponse UploadToApn(string Filepath, Model.AccountAppDotNet account)
        {
            string delegateClientIdOfImgLy = "XaBgfNdXRL6msTWhewgVaMB3BumT22YQ";

            if (File.Exists(Filepath))
            {
                // Read file data
                FileStream fs   = new FileStream(Filepath, FileMode.Open, FileAccess.Read);
                byte[]     data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
                fs.Close();

                Dictionary <string, string> oauthParams = new Dictionary <string, string>();
                oauthParams.Add("grant_type", "delegate");
                oauthParams.Add("delegate_client_id", delegateClientIdOfImgLy);

                Dictionary <string, string> oAuthHeaders = new Dictionary <string, string>();
                oAuthHeaders.Add("Authorization", "Bearer " + account.accessToken);

                WebHelpers.Response oAuthResponse = WebHelpers.SendPostRequest("https://alpha.app.net/oauth/access_token", oauthParams, additionalHeaders: oAuthHeaders);

                oAuthDelegateToken oAuthToken = JsonConvert.DeserializeObject <oAuthDelegateToken>(oAuthResponse.Content);
                if (oAuthToken == null)
                {
                    return(null);
                }



                // Generate post objects
                Dictionary <string, object> postParameters    = new Dictionary <string, object>();
                Dictionary <string, string> additionalHeaders = new Dictionary <string, string>();

                additionalHeaders.Add("Identity-Delegate-Token", oAuthToken.delegate_token);
                additionalHeaders.Add("Identity-Delegate-Endpoint", "https://alpha-api.app.net/stream/0/token");

                postParameters.Add("media", data);



                // Create request and receive response
                HttpWebResponse webResponse = WebHelpers.MultipartFormDataPost("http://img.ly/api/2/upload.json", postParameters, null, additionalHeaders);

                StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                string       fullResponse   = responseReader.ReadToEnd();
                webResponse.Close();
                return(parseResponse(fullResponse));
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        public static bool keylib_activate_get(
            string prod,
            string sregid,
            string email,
            out string keycode,
            out string reason)
        {
            string str1    = "netwinsite.com";
            string str2    = MyKey.keylib_host_new(MyKey.get_host());
            string postUrl = string.Format("http://{0}/cgi-bin/keycgi.exe", (object)str1);

            keycode           = "failed";
            MyKey.robot_email = string.Format("{{host: {0}}}\r\n{{regid: {1}}}\r\n{{email: {2}}}\r\n{{product: {3}}}\r\n{{build: {4}}}\r\n{{hostid: {5}}}\r\n", (object)str2, (object)sregid, (object)email, (object)prod, (object)MyKey.keylib_build_date(), (object)MyKey.s_hostid);
            if (email.Length > 0)
            {
                MyKey.s_email = email;
            }
            reason = "";
            sregid = sregid.ToLower();
            if (sregid.StartsWith("n"))
            {
                sregid = sregid.Substring(1);
            }
            Dictionary <string, object> postParameters = new Dictionary <string, object>();

            postParameters.Add("cmd", (object)"activate");
            postParameters.Add("regid", (object)sregid);
            postParameters.Add(nameof(email), (object)email);
            postParameters.Add("host", (object)str2);
            postParameters.Add("product", (object)prod);
            postParameters.Add("build", (object)MyKey.keylib_build_date());
            postParameters.Add("hostid", (object)MyKey.s_hostid);
            string end;

            try
            {
                string          userAgent       = "ftpdav";
                HttpWebResponse httpWebResponse = WebHelpers.MultipartFormDataPost(postUrl, userAgent, postParameters, "", "");
                end = new StreamReader(httpWebResponse.GetResponseStream()).ReadToEnd();
                httpWebResponse.Close();
                stat.imsg("image post response {0}", (object)end);
            }
            catch (Exception ex)
            {
                stat.imsg("image post failed to connect {0}", (object)ex.ToString());
                return(false);
            }
            keycode = "";
            string str3 = "";

            foreach (string str4 in end.string_lines_any())
            {
                clib.imsg("Response: {0}", (object)str4);
                if (str4.StartsWith("key: "))
                {
                    keycode = str4.Substring(5);
                }
                if (str4.StartsWith("key_state: "))
                {
                    str3 = str4.Substring(1);
                }
                if (str4.StartsWith("error: "))
                {
                    reason = str4.Substring(7);
                }
            }
            if (reason.Length > 0)
            {
                return(false);
            }
            clib.imsg("key state {0}", (object)str3);
            MyKey.s_code = keycode;
            return(true);
        }