Search code examples
c#.nethttpwebrequestrest-client

getting response as a string c#.net


i have created the website with c#.net in a page load event as

protected void Page_Load(object sender, EventArgs e)
    {

        string s = "completed.";
        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);

        Response.OutputStream.Write(bytes, 0, bytes.Length);
    }

when i am running through browser i am getting a correct response as

Completed.

Now my question is when i run the same url through rest client i am getting the Response nody[raw] as

completed.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head><title>

</title></head>

<body>
    <form method="post" action="Default.aspx" id="form1">

<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZJy1PJCY5kS9nkQAfBTgrw0zeG/yMEs2VJP+7kbHC2Yp" />
</div>    <div> </div>    </form></body></html>

but i need to get only completed. as response

how is it possible ?

Waiting for your valuable comments and suggestions


Solution

  • Try to use:

    Response.Clear();
    Response.OutputStream.Write(bytes, 0, bytes.Length); 
    Response.End();