コード例 #1
0
        public void get(Uri uri, Dictionary <String, String> extra_headers, RESTSuccessCallback success_callback, RESTErrorCallback error_callback)
        {
            HttpWebRequest request = WebRequest.CreateHttp(uri);

            if (extra_headers != null)
            {
                foreach (String header in extra_headers.Keys)
                {
                    try
                    {
                        request.Headers[header] = extra_headers[header];
                    }
                    catch (Exception) { }
                }
            }

            request.BeginGetResponse((IAsyncResult result) =>
            {
                HttpWebRequest req = result.AsyncState as HttpWebRequest;
                if (req != null)
                {
                    try
                    {
                        WebResponse response = req.EndGetResponse(result);
                        success_callback(response.GetResponseStream());
                    }
                    catch (WebException e)
                    {
                        error_callback(e.Message);
                        return;
                    }
                }
            }, request);
        }
コード例 #2
0
        public static void post_image(Uri uri, Stream image_stream, RESTSuccessCallback success, RESTErrorCallback error)
        {
            HttpWebRequest request = WebRequest.CreateHttp(uri);

            request.ContentType = "image/jpeg";
            request.Method      = "POST";

            request.BeginGetRequestStream((IAsyncResult result) =>
            {
                HttpWebRequest preq = result.AsyncState as HttpWebRequest;
                if (preq != null)
                {
                    Stream postStream = preq.EndGetRequestStream(result);

                    image_stream.CopyTo(postStream);
                    image_stream.Close();
                    postStream.Close();

                    preq.BeginGetResponse((IAsyncResult final_result) =>
                    {
                        HttpWebRequest req = final_result.AsyncState as HttpWebRequest;
                        if (req != null)
                        {
                            try
                            {
                                WebResponse response = req.EndGetResponse(final_result);
                                success(response.GetResponseStream());
                            }
                            catch (WebException e)
                            {
                                error(e.Message);
                                return;
                            }
                        }
                    }, preq);
                }
            }, request);
        }
コード例 #3
0
        public static void post(Uri uri, Dictionary <String, String> post_params, Dictionary <String, String> extra_headers, RESTSuccessCallback success_callback, RESTErrorCallback error_callback)
        {
            HttpWebRequest request = WebRequest.CreateHttp(uri);

            request.ContentType = "application/x-www-form-urlencoded";
            request.Method      = "POST";

            if (extra_headers != null)
            {
                foreach (String header in extra_headers.Keys)
                {
                    try
                    {
                        request.Headers[header] = extra_headers[header];
                    }
                    catch (Exception) { }
                }
            }


            request.BeginGetRequestStream((IAsyncResult result) =>
            {
                HttpWebRequest preq = result.AsyncState as HttpWebRequest;
                if (preq != null)
                {
                    Stream postStream = preq.EndGetRequestStream(result);

                    StringBuilder postParamBuilder = new StringBuilder();
                    if (post_params != null)
                    {
                        foreach (String key in post_params.Keys)
                        {
                            postParamBuilder.Append(String.Format("{0}={1}&", key, post_params[key]));
                        }
                    }

                    Byte[] byteArray = Encoding.UTF8.GetBytes(postParamBuilder.ToString());

                    postStream.Write(byteArray, 0, byteArray.Length);
                    postStream.Close();


                    preq.BeginGetResponse((IAsyncResult final_result) =>
                    {
                        HttpWebRequest req = final_result.AsyncState as HttpWebRequest;
                        if (req != null)
                        {
                            try
                            {
                                WebResponse response = req.EndGetResponse(final_result);
                                success_callback(response.GetResponseStream());
                            }
                            catch (WebException e)
                            {
                                error_callback(e.Message);
                                return;
                            }
                        }
                    }, preq);
                }
            }, request);
        }
コード例 #4
0
        public static void post_image(Uri uri, Stream image_stream, string which_camera, string from_whom, RESTSuccessCallback success, RESTErrorCallback error)
        {
            HttpWebRequest request = WebRequest.CreateHttp(uri);

            request.ContentType = "image/jpeg";
            request.Method      = "POST";

            request.Headers["X-luxapose-phone-type"] = "lumia_1020";
            request.Headers["X-luxapose-camera"]     = which_camera;
            request.Headers["X-luxapose-user"]       = from_whom;

            // http://stackoverflow.com/questions/13975315/get-unique-device-id-udid-under-windows-phone-8
            byte[] myDeviceID       = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
            string DeviceIDAsString = Convert.ToBase64String(myDeviceID);

            request.Headers["X-luxapose-device-uuid"] = DeviceIDAsString;

            request.BeginGetRequestStream((IAsyncResult result) =>
            {
                HttpWebRequest preq = result.AsyncState as HttpWebRequest;
                if (preq != null)
                {
                    Stream postStream = preq.EndGetRequestStream(result);

                    image_stream.CopyTo(postStream);
                    image_stream.Close();
                    postStream.Close();

                    preq.BeginGetResponse((IAsyncResult final_result) =>
                    {
                        HttpWebRequest req = final_result.AsyncState as HttpWebRequest;
                        if (req != null)
                        {
                            try
                            {
                                WebResponse response = req.EndGetResponse(final_result);
                                success(response.GetResponseStream());
                            }
                            catch (WebException e)
                            {
                                error(e.Message);
                                return;
                            }
                        }
                    }, preq);
                }
            }, request);
        }
コード例 #5
0
        public void get(Uri uri, Dictionary<String, String> extra_headers, RESTSuccessCallback success_callback, RESTErrorCallback error_callback)
        {
            HttpWebRequest request = WebRequest.CreateHttp(uri);

            if (extra_headers != null)
                foreach (String header in extra_headers.Keys)
                    try
                    {
                        request.Headers[header] = extra_headers[header];
                    }
                    catch (Exception) { }

            request.BeginGetResponse((IAsyncResult result) =>
            {
                HttpWebRequest req = result.AsyncState as HttpWebRequest;
                if (req != null)
                {
                    try
                    {
                        WebResponse response = req.EndGetResponse(result);
                        success_callback(response.GetResponseStream());
                    }
                    catch (WebException e)
                    {
                        error_callback(e.Message);
                        return;
                    }
                }
            }, request);
        }
コード例 #6
0
        public static void post_image(Uri uri, Stream image_stream, string which_camera, string from_whom, RESTSuccessCallback success, RESTErrorCallback error)
        {
            HttpWebRequest request = WebRequest.CreateHttp(uri);
            request.ContentType = "image/jpeg";
            request.Method = "POST";

            request.Headers["X-luxapose-phone-type"] = "lumia_1020";
            request.Headers["X-luxapose-camera"] = which_camera;
            request.Headers["X-luxapose-user"] = from_whom;

            // http://stackoverflow.com/questions/13975315/get-unique-device-id-udid-under-windows-phone-8
            byte[] myDeviceID = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
            string DeviceIDAsString = Convert.ToBase64String(myDeviceID);
            request.Headers["X-luxapose-device-uuid"] = DeviceIDAsString;

            request.BeginGetRequestStream((IAsyncResult result) =>
            {
                HttpWebRequest preq = result.AsyncState as HttpWebRequest;
                if (preq != null)
                {
                    Stream postStream = preq.EndGetRequestStream(result);

                    image_stream.CopyTo(postStream);
                    image_stream.Close();
                    postStream.Close();

                    preq.BeginGetResponse((IAsyncResult final_result) =>
                    {
                        HttpWebRequest req = final_result.AsyncState as HttpWebRequest;
                        if (req != null)
                        {
                            try
                            {
                                WebResponse response = req.EndGetResponse(final_result);
                                success(response.GetResponseStream());
                            }
                            catch (WebException e)
                            {
                                error(e.Message);
                                return;
                            }
                        }
                    }, preq);
                }
            }, request);
        }
コード例 #7
0
        public static void post(Uri uri, Dictionary<String, String> post_params, Dictionary<String, String> extra_headers, RESTSuccessCallback success_callback, RESTErrorCallback error_callback)
        {
            HttpWebRequest request = WebRequest.CreateHttp(uri);
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "POST";

            if (extra_headers != null)
                foreach (String header in extra_headers.Keys)
                    try
                    {
                        request.Headers[header] = extra_headers[header];
                    }
                    catch (Exception) { }

            request.BeginGetRequestStream((IAsyncResult result) =>
            {
                HttpWebRequest preq = result.AsyncState as HttpWebRequest;
                if (preq != null)
                {
                    Stream postStream = preq.EndGetRequestStream(result);

                    StringBuilder postParamBuilder = new StringBuilder();
                    if (post_params != null)
                        foreach (String key in post_params.Keys)
                            postParamBuilder.Append(String.Format("{0}={1}&", key, post_params[key]));

                    Byte[] byteArray = Encoding.UTF8.GetBytes(postParamBuilder.ToString());

                    postStream.Write(byteArray, 0, byteArray.Length);
                    postStream.Close();

                    preq.BeginGetResponse((IAsyncResult final_result) =>
                    {
                        HttpWebRequest req = final_result.AsyncState as HttpWebRequest;
                        if (req != null)
                        {
                            try
                            {
                                WebResponse response = req.EndGetResponse(final_result);
                                success_callback(response.GetResponseStream());
                            }
                            catch (WebException e)
                            {
                                error_callback(e.Message);
                                return;
                            }
                        }
                    }, preq);
                }
            }, request);
        }