public static string PostLocation(GPSTrackPoint location, string icon)
        {
            string result = "";

            // HTTP用WebRequestの作成
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(PostURI);

            req.Method          = WebRequestMethods.Http.Post;
            req.Credentials     = new NetworkCredential(Properties.Settings.Default.User, Properties.Settings.Default.Password);
            req.PreAuthenticate = true;
            req.Timeout         = 6000;
            req.ContentType     = "application/x-www-form-urlencoded";
            req.UserAgent       = version + " " + Properties.Settings.Default.User;
            if (Properties.Settings.Default.ProxyServer.Length > 0)
            {
                req.Proxy = new WebProxy(string.Format("http://{0}:{1}", Properties.Settings.Default.ProxyServer, Properties.Settings.Default.ProxyPort));
            }

            // HTTPで送信するデータ
            string body = location.GetHttpParameter() + "&save=" + (Properties.Settings.Default.ServerSave ? "1" : "0") + "&t=" + Util.GetIconType(icon);

            // 送信データを書き込む
            req.ContentLength = body.Length;
            using (StreamWriter sw = new StreamWriter(req.GetRequestStream()))
            {
                sw.Write(body);
            }

            // レスポンスを取得
            WebResponse res = req.GetResponse();

            using (StreamReader sr = new StreamReader(res.GetResponseStream()))
            {
                result = sr.ReadLine();
                if (result == null)
                {
                    result = "null result.";
                }
            }
            if (Properties.Settings.Default.SoundPost != "")
            {
                Util.PlaySEFromFile(Properties.Settings.Default.SoundPost);
            }
            else
            {
                Util.PlaySE("PCGPS.Resources.b_067.wav");
            }
            return(result);
        }
        public static string PostLocation(GPSTrackPoint location, string icon)
        {
            string result = "";

            // HTTP用WebRequestの作成
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(PostURI);
            req.Method = WebRequestMethods.Http.Post;
            req.Credentials = new NetworkCredential(Properties.Settings.Default.User, Properties.Settings.Default.Password);
            req.PreAuthenticate = true;
            req.Timeout = 6000;
            req.ContentType = "application/x-www-form-urlencoded";
            req.UserAgent = version + " " + Properties.Settings.Default.User;
            if (Properties.Settings.Default.ProxyServer.Length > 0)
            {
                req.Proxy = new WebProxy(string.Format("http://{0}:{1}", Properties.Settings.Default.ProxyServer, Properties.Settings.Default.ProxyPort));
            }

            // HTTPで送信するデータ
            string body = location.GetHttpParameter() + "&save=" + (Properties.Settings.Default.ServerSave ? "1" : "0") +"&t=" + Util.GetIconType(icon);

            // 送信データを書き込む
            req.ContentLength = body.Length;
            using (StreamWriter sw = new StreamWriter(req.GetRequestStream()))
            {
                sw.Write(body);
            }

            // レスポンスを取得
            WebResponse res = req.GetResponse();
            using (StreamReader sr = new StreamReader(res.GetResponseStream()))
            {
                result = sr.ReadLine();
                if (result == null)
                {
                    result = "null result.";
                }
            }
            if (Properties.Settings.Default.SoundPost != "")
            {
                Util.PlaySEFromFile(Properties.Settings.Default.SoundPost);
            }
            else
            {
                Util.PlaySE("PCGPS.Resources.b_067.wav");
            }
            return result;
        }
Beispiel #3
0
        public static string Tweet(string status, GPSTrackPoint location)
        {
            string result;
            string url = "https://api.twitter.com/1.1/statuses/update.json";

            Dictionary <string, string> postData = new Dictionary <string, string>();

            //postData.Add("status", Util.URLEncode(status));
            postData.Add("status", status);
            if (Properties.Settings.Default.LocationTwit)
            {
                postData.Add("lat", Math.Round(location.Latitude, 6).ToString());
                postData.Add("long", Math.Round(location.Longitude, 6).ToString());
            }

            Dictionary <string, string> headers = TwitterOAuth.getInstance().createOAuthHeader("POST", url, postData);
            StringBuilder sb    = new StringBuilder();
            bool          first = true;

            foreach (string key in postData.Keys)
            {
                if (!first)
                {
                    sb.Append("&");
                }
                else
                {
                    first = false;
                }
                sb.Append(String.Format("{0}={1}", key, Util.URLEncode(postData[key])));
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.ServicePoint.Expect100Continue = false;
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method      = WebRequestMethods.Http.Post;
            request.Timeout     = 8000;
            foreach (string key in headers.Keys)
            {
                request.Headers.Add(key, headers[key]);
            }

            if (Properties.Settings.Default.ProxyServer.Length > 0)
            {
                request.Proxy = new WebProxy(string.Format("http://{0}:{1}", Properties.Settings.Default.ProxyServer, Properties.Settings.Default.ProxyPort));
            }

            byte[] bytes = Encoding.ASCII.GetBytes(sb.ToString());
            request.ContentLength = bytes.Length;
            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(bytes, 0, bytes.Length);
            }

            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    result = reader.ReadToEnd();
                }
            }
            return(result);
        }
Beispiel #4
0
 /// <summary>
 /// 位置情報が更新されたときに呼び出される。
 /// メインスレッドとは別のスレッドで呼び出されるので、UIを扱うときは注意
 /// </summary>
 /// <param name="location"></param>
 public abstract void OnLocationChanged(GPSTrackPoint location);
        public static string Tweet(string status, GPSTrackPoint location)
        {
            string result;
            string url = "https://api.twitter.com/1.1/statuses/update.json";

            Dictionary<string, string> postData = new Dictionary<string, string>();
            //postData.Add("status", Util.URLEncode(status));
            postData.Add("status", status);
            if (Properties.Settings.Default.LocationTwit)
            {
                postData.Add("lat", Math.Round(location.Latitude, 6).ToString());
                postData.Add("long", Math.Round(location.Longitude, 6).ToString());
            }

            Dictionary<string, string> headers = TwitterOAuth.getInstance().createOAuthHeader("POST", url, postData);
            StringBuilder sb = new StringBuilder();
            bool first = true;
            foreach (string key in postData.Keys)
            {
                if (!first)
                {
                    sb.Append("&");
                }
                else
                {
                    first = false;
                }
                sb.Append(String.Format("{0}={1}", key, Util.URLEncode( postData[key] )));
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.ServicePoint.Expect100Continue = false;
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = WebRequestMethods.Http.Post;
            request.Timeout = 8000;
            foreach (string key in headers.Keys)
            {
                request.Headers.Add(key, headers[key]);
            }

            if (Properties.Settings.Default.ProxyServer.Length > 0)
            {
                request.Proxy = new WebProxy(string.Format("http://{0}:{1}", Properties.Settings.Default.ProxyServer, Properties.Settings.Default.ProxyPort));
            }

            byte[] bytes = Encoding.ASCII.GetBytes(sb.ToString());
            request.ContentLength = bytes.Length;
            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(bytes, 0, bytes.Length);
            }

            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    result = reader.ReadToEnd();
                }
            }
            return result;
        }