Reputation: 71
When I am calling postAsync with particular image url, I am seeing the below error in json response.
"Invalid image URL or error downloading from target server. Remote server error returned: "An error occurred while sending the request.""
Below is the Image Url : http://localhost:3942/WebImages/201658211024test.jpg
Below is the code :
var uri = "https://api.projectoxford.ai/face/v1.0/detect?" + queryString;
string jsonbody = "{\"url\":\"" + imageUrl + "\"}";
byte[] byteData = Encoding.UTF8.GetBytes(jsonbody);
var content = new ByteArrayContent(byteData);
content.Headers.ContentType =
new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
response = await client.PostAsync(uri, content);
string json = await response.Content.ReadAsStringAsync();
Can you please let me know what is the issue? Is it because the image url has the format type at the end ? If so, how can I fix this ?
Upvotes: 0
Views: 1503
Reputation: 2973
When you make a request to the Cognitive Service API with an image URL as you've specified, you're instructing the service running in the cloud to load the image from that location. The service cannot locate your localhost, hence the error.
You have two options: (a) if your image is already available at a public-reachable URL, use the URL instead. If you're unsure whether the URL is publicly reachable, try entering it in a browser on your phone, for example. Alternatively, (b) Upload the image in the HTTP request body. You'll need to also set the MediaTypeHeaderValue to application/octet-stream
.
If you're using a managed language (like C#) with Visual Studio, consider using the NuGet package. This will take care of the details for you. The source for that NuGet package is on GitHub.
Upvotes: 2