Error 500 continues when attempting BindHTML

I am really frustrated. Looking at all the various posts, you point to a variety of different places on your site and your examples are very inconsistent. In anycase, the code below is gleaned directly from your site… and does not work. I continue to get 500 server errors. This is a .net 2.0 environment with a login, hence the need for the credentials line. Please help!

Dim MyURL As Uri
MyURL = Request.Url

Try
Dim client As New System.Net.WebClient()
client.Credentials = System.Net.CredentialCache.DefaultCredentials
pdf.Credentials = client.Credentials

Dim myDataBuffer() As Byte = client.DownloadData(MyURL.AbsoluteUri)
Dim postStream As New MemoryStream(myDataBuffer)
pdf.BindHTML(postStream)

pdf.Save(ConfigurationManager.AppSettings(“DataFolderPath”) & “COIPDFTest.pdf”)

Catch ex As Exception
ret = ex.Message

End Try

Hi,

Thank you for considering Aspose.

Can you please provide some test URL to us and let us investigate this issue.

Thanks.

Please login to

http://www.crtonline.org/faculty

username: [support@aspose.com], password: 12345

Select ‘Conflict of Interest’ from the list box on the left.

Click the acknowledgement button to make the pop up go away.

Click 'No I/we have no conflicts… radiobutton at the top (this has validation on it and you cannot submit until one of those options is selected.

Scroll to the bottom of the screen. There is a .net button titled ‘Button’ and a label to the right that will display the error message after the button is clicked. When you click the button, here is the exact code that is executing…

Try

Dim client As New System.Net.WebClient()

client.Credentials = System.Net.CredentialCache.DefaultCredentials

pdf.Credentials = client.Credentials

Dim myDataBuffer() As Byte = client.DownloadData(MyURL.AbsoluteUri)

Dim postStream As New MemoryStream(myDataBuffer)

pdf.BindHTML(postStream)

pdf.Save(ConfigurationManager.AppSettings("DataFolderPath") & "COIPDFTest.pdf")

Catch ex As Exception

ret = ex.Message

errMsg.Text = ret

End Try

Aspose.PDF.dll 3.6.2.0 dated 2/14/2008

PS. completely separeate subject - this forum is currently not accepting posting done on a Macintosh with latest version of Firefox.

Hi,

Thanks for more information. I will check it and will get back to you.

Thanks.

Hi,

I tested with the following code without using Aspose.Pdf

Dim client As New System.Net.WebClient
client.Credentials = New NetworkCredential("support@aspose.com", "12345")
Dim myDataBuffer() As Byte = client.DownloadData("http://www.crtonline.org/faculty")

and I get the same error. So I think this error is not caused by Aspose.Pdf.

I was using clientCredential - not NetworkCredential - does that make a difference?

In looking at your example, you are pointing at a folder, rather than any particular .aspx file per the instructions I provided, so that is likely a problem. Do you have a complete working sample that actually saves a ASPX to PDF. Your online documentation, if used exactly as provided (combined with the client.credentials security code, does not work.

Hi,

We investigate this issue and found UserAgent should be set for this web site. Please try writing your code like th efollowing:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.crtonline.org/faculty");<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

//Set properties for HttpWebRequest, must set UserAgent property when accessing some website,

//otherwise you will receive HTTP 500 error

request.Credentials = CredentialCache.DefaultCredentials;

request.ReadWriteTimeout = 70000;

request.Timeout = 60000;

request.ContentType = "text/html";

request.UserAgent = HttpContext.Current.Request.UserAgent; //VERY IMPORTANT!

//Get Response

HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();

//Get the stream associated with the response.

Stream receiveStream = webResponse.GetResponseStream();

//Pipes the stream to a higher level stream reader with the required encoding format.

StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);

//Read page content.

string receiveStr = readStream.ReadToEnd();

//... use Aspose.Pdf to deal with the receive page content

The message I get now is - Illegal characters - is this due to the fact that there are things such as div tags and javascript in the source file?

I tried with the following code and it works. But currently Aspose.Pdf supports simple HTML only. We are working on improving this feature now.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.crtonline.org/faculty");<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

//Set properties for HttpWebRequest, must set UserAgent property when accessing some website,

//otherwise you will receive HTTP 500 error

request.Credentials = CredentialCache.DefaultCredentials;

request.ReadWriteTimeout = 70000;

request.Timeout = 60000;

request.ContentType = "text/html";

request.UserAgent = HttpContext.Current.Request.UserAgent; //VERY IMPORTANT!

//Get Response

HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();

//Get the stream associated with the response.

Stream receiveStream = webResponse.GetResponseStream();

//Pipes the stream to a higher level stream reader with the required encoding format.

StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);

System.DateTime begin = System.DateTime.Now;

Pdf p = new Pdf();

p.BindHTML(readStream);

p.Save("e:/temp/test.pdf");