private async Task MakePredictionAsync(string fileName)
{
string url = "입력하세요";
string prediction_key = "입력하세요";
string content_type = "application/octet-stream";
var file = File.ReadAllBytes(fileName);
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("prediction-key", prediction_key);
using (var content = new ByteArrayContent(file))
{
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(content_type);
HttpResponseMessage response = await client.PostAsync(url, content);
var responseString = await response.Content.ReadAsStringAsync();
}
}
}
2.
var responseString = await response.Content.ReadAsStringAsync();
3.
using (HttpClient client = new HttpClient())
{
//HTTP 요청 헤더에 "prediction-key" 사용자 정의 헤더 추가
client.DefaultRequestHeaders.Add("Prediction-Key", prediction_key);
using (ByteArrayContent content = new ByteArrayContent(file))
{
// content 헤더에 content 타입 지정
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(content_type);
// 요청 (HTTP POST 비동기)
// url: 요청 보낼 서버 주소 (API 엔드포인트), content: HTTP 요청 내용(+이미지)
HttpResponseMessage response = await client.PostAsync(url, content);
// 응답 (문자열(String) 형태로 읽음)
var responseString = await response.Content.ReadAsStringAsync();
}
}