W
Will .H
Guest
Hi there,
I have an outlook addin and get ready to connect Azure API, I list out the code for you to look at. When the code runs to this line:
> using (Stream requestStream = webapiRequest.GetRequestStream())
it shows me the error message "Unable to connect to the remote server" ... Does anyone have any idea on it.??
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
byte[] bytes = Encoding.UTF8.GetBytes(postData);
var webapiUriRequest = (HttpWebRequest)WebRequest.Create(new Uri(WebAPIUrl));
var webapiRequest = (HttpWebRequest)webapiUriRequest;
webapiRequest.PreAuthenticate = true;
webapiRequest.Headers.Add("Authorization",
Convert.ToBase64String(Encoding.UTF8.GetBytes(WebAPIAccessAccount + ":" + WebAPIAccessPassword)));
webapiRequest.Method = "POST";
webapiRequest.ContentType = "application/json";
webapiRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
webapiRequest.KeepAlive = false;
using (Stream requestStream = webapiRequest.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Count());
}
using (HttpWebResponse webapiResponse = (HttpWebResponse)webapiRequest.GetResponse())
{
if (webapiResponse.StatusCode != HttpStatusCode.OK)
{
throw new ApplicationException(webapiResponse.StatusCode.ToString());
}
}
Hi there, if you found my comment very helpful then please | Propose as answer | . Thanks and Regards.
Continue reading...
I have an outlook addin and get ready to connect Azure API, I list out the code for you to look at. When the code runs to this line:
> using (Stream requestStream = webapiRequest.GetRequestStream())
it shows me the error message "Unable to connect to the remote server" ... Does anyone have any idea on it.??
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
byte[] bytes = Encoding.UTF8.GetBytes(postData);
var webapiUriRequest = (HttpWebRequest)WebRequest.Create(new Uri(WebAPIUrl));
var webapiRequest = (HttpWebRequest)webapiUriRequest;
webapiRequest.PreAuthenticate = true;
webapiRequest.Headers.Add("Authorization",
Convert.ToBase64String(Encoding.UTF8.GetBytes(WebAPIAccessAccount + ":" + WebAPIAccessPassword)));
webapiRequest.Method = "POST";
webapiRequest.ContentType = "application/json";
webapiRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
webapiRequest.KeepAlive = false;
using (Stream requestStream = webapiRequest.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Count());
}
using (HttpWebResponse webapiResponse = (HttpWebResponse)webapiRequest.GetResponse())
{
if (webapiResponse.StatusCode != HttpStatusCode.OK)
{
throw new ApplicationException(webapiResponse.StatusCode.ToString());
}
}
Hi there, if you found my comment very helpful then please | Propose as answer | . Thanks and Regards.
Continue reading...