예제 #1
0
        public static ResultType PostData <ResultType>(PostReq_Param p) where ResultType : class
        {
            ResultType _reqRet = null;
            string     re      = null;

            try
            {
                using (var wc = new WebClient())
                {
                    //post
                    var postData = JsonConvert.SerializeObject(p.data);
                    var bytes    = Encoding.UTF8.GetBytes(postData);
                    wc.Headers.Add("Content-Type", "application/json; charset=utf-8");
                    wc.Headers.Add("ContentLength", postData.Length.ToString());
                    var responseData = wc.UploadData($"{p.InterfaceName}", "POST", bytes);
                    re      = Encoding.UTF8.GetString(responseData);
                    _reqRet = JsonConvert.DeserializeObject <ResultType>(re);
                }
            }
            catch (Exception e)
            {
                Logger.Log(e);
                if (!string.IsNullOrEmpty(re))
                {
                    Logger.Log("re:" + re);
                }
            }
            return(_reqRet);
        }
예제 #2
0
파일: TulingAI.cs 프로젝트: Dolany/DolanyAI
        private PostReq_Param GetPostReq(MsgInformationEx MsgDTO, string ApiKey)
        {
            var bindAi     = BindAiSvc[MsgDTO.BindAi];
            var imageInfo  = ParseImgText(MsgDTO.FullMsg, bindAi.ImagePath);
            var perception = string.IsNullOrEmpty(imageInfo)
                ? new perceptionData
            {
                InputText = new inputTextData
                {
                    Text = MsgDTO.FullMsg
                }
            }
                : new perceptionData
            {
                InputImage = new inputImageData
                {
                    Url = imageInfo
                }
            };

            var post = new PostReq_Param
            {
                InterfaceName = RequestUrl,
                data          = new TulingRequestData
                {
                    ReqType    = 0,
                    Perception = perception,
                    UserInfo   = new userInfoData
                    {
                        ApiKey = ApiKey,
                        UserId = MsgDTO.FromQQ.ToString()
                    }
                }
            };

            return(post);
        }