[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Grabbing content from an external web server

Posted on 2004-10-03
3
Medium Priority
?
393 Views
Last Modified: 2008-03-03
The application in question is ASP.NET / C#. I have a webform with some text boxes, and it submits via the POST method to a web server out of my control. That web server displays a report in html to the user in the browser window.

What I would like to do is:

- Keep the user on my site instead of leaving to the other site.
- Save the contents of the report to a database.
- Show the report in a new browser window from the content stored in the database in the previous step.

Can somebody point me in the right direction on how to do this?
0
Comment
Question by:MetaDataY
3 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12213532
Try using this function to grab the content:

Function GetHTML(strURL)
      Dim objXMLHTTP, strReturn
      Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
      objXMLHTTP.Open "GET", strURL, False
      objXMLHTTP.Send
      strReturn = objXMLHTTP.responseText
      Set objXMLHTTP = Nothing
      GetHTML = strReturn
End Function
0
 
LVL 5

Accepted Solution

by:
ajitanand earned 1400 total points
ID: 12214693
fritz - your solution relates to ASP and that too for just HTTP GET. FOR ASP.Net+C# + HTTP POST, here is my approach:


1. Get the text box values and submit these to the remote server using the dot net webclient class
-------------------------------------
public void PostFormData(){
      string uriString = "http://myremoteserver.com/report.asp";

      // Create a new WebClient instance.

      WebClient myWebClient = new WebClient();

      //data to be posted to the URI
      //You will get this form TextBox1.Text and so on...
      string myTextBox1Value = "somevalue";
      string myTextBox2Value = "somevalue";
      string myTextBox3Value = "somevalue";
      
      //Build the post data in url encoded format
      string postData = "TextBox1=" + HttpUtility.UrlEncode(myTextBox1Value) +
            "&TextBox2=" + HttpUtility.UrlEncode(myTextBox2Value) +
            "&TextBox3=" + HttpUtility.UrlEncode(myTextBox3Value);

      myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");

      // Apply ASCII Encoding to obtain the string as a byte array.
      byte[] byteArray = Encoding.ASCII.GetBytes(postData);

      // Upload the input string using the HTTP 1.0 POST method.
      byte[] responseArray = myWebClient.UploadData(uriString,"POST",byteArray);
      myWebClient.Dispose();

      // Get and Decode the response.
      string myResponseText = Encoding.ASCII.GetString(responseArray);
      
      //display the response, if you want
      //Response.Write(myResponseText);
      
      //store it in your db as well
      //some db updates... here...
      //and lets assume you get the new report record ID as myresponsetextID after storing in DB
      
      //write the following javascript that opens a new popup window (another aspx page),
      //that will throw the response content we stored here in the db
      //Response.Write("<script" = ">window.open('reportpage.aspx?recordid=" + myresponsetextID +"','report');</" + "script>");

      //Done!
}


2. Now you have stored the page output in your db, and a pop up appears for the user that points to another page (reportpage.aspx with a querystring parameter - recordid). This page will read the database content (the response stored earlier) and render it to the client.

-------------------


Hope this helps.

rgds,
Ajit Anand
0
 

Author Comment

by:MetaDataY
ID: 12214877
Ajit Anand, that's what I'm looking for. I had actually found how to do this with HttpWebRequest and HttpWebResponse, where you have to specify content length and stream to the request and streamread the response. WebClient seems to be even easier.

Thank you both for your input!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question