Created
November 26, 2018 15:30
-
-
Save kenny-evitt/9c55302121127f7f9b015f9482a95716 to your computer and use it in GitHub Desktop.
C# web request example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool CallGenerateImageOfFirstPageWebMethod(int documentLocationId) | |
{ | |
HttpWebRequest request = | |
(HttpWebRequest)WebRequest.Create( | |
String.Format( | |
"http://snyiis1/Apps/documents/{0}/generate-preview-image", | |
documentLocationId)); | |
request.Method = "POST"; | |
request.ContentLength = 0; | |
HttpWebResponse response = null; | |
string responseContent = null; | |
try | |
{ | |
response = (HttpWebResponse)request.GetResponse(); | |
using (StreamReader responseStreamReader = new StreamReader(response.GetResponseStream())) | |
{ | |
responseContent = responseStreamReader.ReadToEnd(); | |
} | |
} | |
catch (Exception ex) | |
{ | |
ex.Dump(); | |
response.Dump(); | |
responseContent.Dump(); | |
return false; | |
} | |
return | |
response != null | |
&& response.StatusCode == HttpStatusCode.OK | |
&& responseContent == "{\"status\":\"true\"}"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment