I'm using this API that accepts an image and sends back the description of it's contents. According to the docs, the cURL looks like this:
curl -i -X POST \
-H "Authorization: CloudSight [key]" \
-F "image_request[image]=@Image.jpg" \
-F "image_request[locale]=en-US" \
https://api.cloudsightapi.com/image_requests
My code for sending the request is as below:
var request = (HttpWebRequest)WebRequest.Create(cloudsight_url);
request.Method = "POST";
request.Headers.Add("Authorization", "CloudSight R6USrcKxMym0EP2peuYtVA");
string s1 = string.Format("image_request[locale]={0}&image_request[remote_image_url]={1}", "en-US", imgurl);
// Send Data
StreamWriter myWriter = null;
myWriter = new StreamWriter(request.GetRequestStream());
myWriter.Write(s1);
myWriter.Close();
var response1 = (HttpWebResponse)request.GetResponse();
string result2 = "";
using (StreamReader streamReader = new StreamReader(response1.GetResponseStream()))
{
var output = streamReader.ReadToEnd();
streamReader.Close();
result2 = output.ToString();
}
The request is sent successfully, however the service returns { "status" : "not completed" }
. In the docs, it says to continue polling for a response until the { "status" : "completed" }
response is returned. How do I acheive this?