Click here to Skip to main content
15,913,311 members
Home / Discussions / C#
   

C#

 
AnswerRe: Auto reply when we sent request to server Pin
Dave Kreskowiak20-May-20 18:19
mveDave Kreskowiak20-May-20 18:19 
Questioncan any one help me with this WS? Pin
Member 1337716619-May-20 19:19
Member 1337716619-May-20 19:19 
AnswerRe: can any one help me with this WS? Pin
Dave Kreskowiak20-May-20 3:28
mveDave Kreskowiak20-May-20 3:28 
AnswerRe: can any one help me with this WS? Pin
DerekT-P24-May-20 3:55
professionalDerekT-P24-May-20 3:55 
GeneralRe: can any one help me with this WS? Pin
Member 1337716626-May-20 19:22
Member 1337716626-May-20 19:22 
GeneralRe: can any one help me with this WS? Pin
DerekT-P26-May-20 23:20
professionalDerekT-P26-May-20 23:20 
QuestionHow to Validate Rest API response? Pin
Member 1477996819-May-20 8:49
Member 1477996819-May-20 8:49 
AnswerRe: How to Validate Rest API response? Pin
kalberts19-May-20 9:31
kalberts19-May-20 9:31 
GeneralRe: How to Validate Rest API response? Pin
Member 1477996819-May-20 9:46
Member 1477996819-May-20 9:46 
QuestionRe: How to Validate Rest API response? Pin
Eddy Vluggen19-May-20 11:29
professionalEddy Vluggen19-May-20 11:29 
GeneralRe: How to Validate Rest API response? Pin
kalberts19-May-20 11:39
kalberts19-May-20 11:39 
GeneralMessage Closed Pin
19-May-20 12:22
Member 1477996819-May-20 12:22 
GeneralRe: How to Validate Rest API response? Pin
Eddy Vluggen19-May-20 14:25
professionalEddy Vluggen19-May-20 14:25 
GeneralRe: How to Validate Rest API response? Pin
Member 1477996819-May-20 14:40
Member 1477996819-May-20 14:40 
GeneralRe: How to Validate Rest API response? Pin
Eddy Vluggen19-May-20 14:45
professionalEddy Vluggen19-May-20 14:45 
QuestionRe: How to Validate Rest API response? Pin
Eddy Vluggen19-May-20 14:23
professionalEddy Vluggen19-May-20 14:23 
AnswerRe: How to Validate Rest API response? Pin
Member 1477996819-May-20 14:43
Member 1477996819-May-20 14:43 
GeneralRe: How to Validate Rest API response? Pin
Eddy Vluggen19-May-20 14:46
professionalEddy Vluggen19-May-20 14:46 
GeneralRe: How to Validate Rest API response? Pin
Member 1477996819-May-20 14:44
Member 1477996819-May-20 14:44 
AnswerRe: How to Validate Rest API response? Pin
Eddy Vluggen19-May-20 11:28
professionalEddy Vluggen19-May-20 11:28 
AnswerRe: How to Validate Rest API response? Pin
Gerry Schmitz19-May-20 19:35
mveGerry Schmitz19-May-20 19:35 
Questionhow to add picture into mysql using datagridview Pin
Member 1483389818-May-20 20:28
Member 1483389818-May-20 20:28 
AnswerRe: how to add picture into mysql using datagridview Pin
Richard MacCutchan18-May-20 21:17
mveRichard MacCutchan18-May-20 21:17 
QuestionRe: how to add picture into mysql using datagridview Pin
Eddy Vluggen19-May-20 0:53
professionalEddy Vluggen19-May-20 0:53 
QuestionDownload a webpage from within C# in exactly the same way a web browser would? Pin
arnold_w17-May-20 22:02
arnold_w17-May-20 22:02 
I'm using the following code to download a webpage:
C#
public static GenericStatusType LoadHttpPageWithBasicAuthentication(string url, string username, string password)
{
    GenericStatusType status = new GenericStatusType(GenericStatusCode.OK, null, "", "");
    try
    {
        Uri myUri = new Uri(url);
        WebRequest myWebRequest = HttpWebRequest.Create(myUri);
        HttpWebRequest myHttpWebRequest = (HttpWebRequest)myWebRequest;
        NetworkCredential myNetworkCredential = new NetworkCredential(username, password);
        CredentialCache myCredentialCache = new CredentialCache();
        myCredentialCache.Add(myUri, "Basic", myNetworkCredential);
        myHttpWebRequest.PreAuthenticate = true;
        myHttpWebRequest.Credentials = myCredentialCache;
        WebResponse myWebResponse = null;
        try
        {
            myWebResponse = myWebRequest.GetResponse();
        }
        catch (WebException e)
        {
            status.errorHeading = "Error Reading Web Page";
            status.errorMsg = "A WebException occurred while trying to read from the following URL: " + url + ". Technical information: " + e.Message;
            status.statusCode = GenericStatusCode.ERROR;
            if (myWebResponse != null)
            {
                myWebResponse.Close();
            }
            return status;
        }

        Stream responseStream = myWebResponse.GetResponseStream();
        StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default);
        string pageContent = myStreamReader.ReadToEnd();
        responseStream.Close();
        myWebResponse.Close();
        status.value = pageContent;
    }
    catch (Exception e)
    {
        status.errorHeading = "Error Reading Web Page";
        status.errorMsg = "An error occurred while trying to read from the following URL: " + url + ". Technical information: " + e.Message;
        status.statusCode = GenericStatusCode.ERROR;
    }
    return status;
}
To my surprise, the string this method returns is different from what I get in Chrome if I do a regular "Save As" from a link to the particular webpage. I can see that when I download from within C#, I get an exception:
<span class="warning">Object reference not set to an instance of an object.. System.NullReferenceException: Object reference not set to an instance of an object
In the html-file that I download through "Save As" the corresponding lines look like this:
<div class="ts-folder-diaginfo"></div><div class="ui grey attached inverted mini menu"><a class="item"
How can I solve this i.e. get the same result from calling LoadHttpPageWithBasicAuthentication as downloading in Chrome using "Save As"?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.