Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Grabbing content from an external web server

Posted on 2004-10-03
3
Medium Priority
?
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

618 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