Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with repsonse.contenttype

Status
Not open for further replies.

UncleScooby

Programmer
Jun 1, 2001
30
GB
I am getting the following error:

Response object error 'ASP 0156 : 80004005'
Header Error
/iibs/testa.asp, line 31
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.



It is the response.contenttype line of code that seems to be triggering it in the code below. (I have loaded ms data access components 2.6 on the server).

Any help is sincerely appreciated.

Uncle S.


<%

Function GetHTML(strURL)
Dim objXMLHTTP, strReturn
Set objXMLHTTP = SErver.CreateObject(&quot;Microsoft.XMLHTTP&quot;)

objXMLHTTP.Open &quot;GET&quot;, strURL, False
objXMLHTTP.Send

strReturn = objXMLHTTP.responseText
Set objXMLHTTP = Nothing

GetHTML = strReturn
End Function

' Write it:
Response.Write GetHTML(&quot;
' Download it:
Response.ContentType = &quot;application/x-msdownload&quot;
Response.AddHeader &quot;Content-Disposition&quot;, &quot;filename=Something.asp&quot;
Response.BinaryWrite GetHTML(&quot;
%>
 
The error your getting is based on the fact that uyou have already sent information to the user. When you first send information ot the user it sends the headers to their browser so that the browser knows what to do with the incoming data. Once those headers have ben sent you cannot alter them, they are already out the door. Since you have a Response.Write first, IIS sends the default headers.

The second problem here is that you cannot display one file and give them a file to download at the same time. Everything you put in the Response buffer belongs tothe same page. One way to solve this would be to write the HTML and a download link. Set up the download link to point to this same page with a querystring variable. Then if you add an if statement to tghis page to check for the querystring variable you ill be able to either give them the HTML or the file download depending on whether that querystring variable was present or not.

-Tarwn

[sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Do you know how hot your computer is running at home? I do
 
also, in addition to Tarwn's suggestions, you can avoid this error with Response.Buffer = True before any page output is done and still redirect/output/change output method without the error, just be sure to Response.Clear and Response.End

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top