예제 #1
0
        public async Task<APIResponseJSON> GetResult()
        {
            string resultJSON;
            // 画像の読み込み/エンコード
            string img = await base64encode(Filename);
            // JSON の生成
            APIRequestJSON req = new APIRequestJSON(img, faceDetection, labelDetection, labelDetection, textDetection, safeSearchDetection, imageProperties);
            /*using (StreamWriter sw = new StreamWriter("request.json"))
            {
                sw.Write(req.RequestJSON);
            }*/
            // リクエスト(JSON で取得)
            resultJSON = await getApiResult(req);// デバッグ時削除


            /*using (StreamReader sr = new StreamReader("sampleresponse.json"))
            {
                resultJSON = sr.ReadToEnd();
            }*/
            APIResponseJSON res = APIResponseJSON.Serialize(resultJSON);
            //var a = res.responses[0].faceAnnotations[0].landmarks[0];


            // JSON を APIResponseJSON へ変換し返却
            //Console.WriteLine(req.RequestJSON);

            return res;
        }
예제 #2
0
        async Task<string> getApiResult(APIRequestJSON reqJSON)
        {
            string result;

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(apiUrl + "?key=" + APIkey);
            //req.AutomaticDecompression = DecompressionMethods.GZip; Universal は無理
            req.Method = "POST";
            using (Stream reqstream = await req.GetRequestStreamAsync())
            {
                byte[] postByteData = Encoding.UTF8.GetBytes(reqJSON.RequestJSON);
                reqstream.Write(postByteData, 0, postByteData.Length);
            }

            using (WebResponse res = await req.GetResponseAsync())
            using (Stream resStream = res.GetResponseStream())
            using (StreamReader sr = new StreamReader(resStream, Encoding.UTF8))
            {
                result = sr.ReadToEnd();
            }
            return result;
        }