示例#1
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="parameter">url参数</param>
        /// <param name="url">访问地址,非参数部分</param>
        /// <returns></returns>
        public RequestResult Translate(RequestParameter parameter, string url = "http://apis.map.qq.com/ws/coord/v1/translate")
        {
            WebClient webClient = new WebClient();

            webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");
            byte[] responseResult = webClient.DownloadData($"{url}{parameter.ToString()}");
            string result         = Encoding.UTF8.GetString(responseResult);

            return(new JavaScriptSerializer().Deserialize <RequestResult>(result));
        }
    /// <summary>
    /// TCPでサーバーに文字列を送信
    /// </summary>
    /// <param name="Msg">送信内容</param>
    /// <returns>送信成功</returns>
    public bool Request(RequestParameter Parameter, string Content)
    {
        string Msg = Parameter.ToString("G") + "=" + Content;

        byte[] bytes = Encoding.UTF8.GetBytes(Msg + '\n');
        try
        {
            socket.Send(bytes);
        }catch
        {
            Debug.LogError("送信できませんでした。切断された可能性があります。");
            return(false);
        }
        return(true);
    }