Solved

How to make an HTTP Post request from inside ASP .Net Page and also trasfer the page

Posted on 2003-11-19
11
4,964 Views
Last Modified: 2007-12-19
Hi,

I am stuck in a situation where I have to make a http web request to another website's web page(asp) from withing the ASP .Net application and also pass the control to that ASP page.

Means I want use HttpWebRequest classes and also want to do server.trasfer. but the final page should be able to get the values passed by using Request.form("values") .

Please guide me.

Thanks

Atul
0
Comment
Question by:digitaldaku
[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
  • 5
  • 4
11 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 9781520
read:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui10012002.asp
http://www.code101.com/Code101/DisplayArticle.aspx?cid=23
<%
     Dim strHTML ' for response
     Dim url ' url to post and redirect to
     url = "http://somedain.com/page1.asp"
     Set objHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
     Call objHTTP.open("GET", url, False)
     Call objHTTP.send
     strHTML = objHTTP.responseText
     Set objHTTP = Nothing
     Response.redirect url
%>

HTH,
CJ
0
 

Author Comment

by:digitaldaku
ID: 9782248
Many thanks for above code.

Using the above code, the receiving page will not able to use request.form("posted values from sending page") .

I want to create a http post and also redirect to the page....so that the receiving page can receive those values.

I cannot use get method since the data will be visible in the URL and is sensitive.

Please help !

Once again thanks

0
 
LVL 19

Expert Comment

by:cheekycj
ID: 9782375
Adding postData is easy.. look at the URLs

Dim postData

postData = "field1=" & request.form("field1")
postData = postData & "&field2=" & request.form("field2")

Call objHTTP.open("POST", url, False)
Call objHTTP.send  "Content-Type", "application/x-www-form-urlencoded"
Call objHTTP.send postData

How is the data visible?

CJ
0
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 

Author Comment

by:digitaldaku
ID: 9783634
Thanks for your immediate response.

I am trying to run this....
What is your opinion?

objRequest = CType(WebRequest.Create("http://xyz/dmz/abc.asp"), HttpWebRequest)
            objRequest.Method = "POST"
            objRequest.ContentType = "application/x-www-form-urlencoded"
            objRequest.MaximumAutomaticRedirections = 1
            objRequest.AllowAutoRedirect = True

            'create message body
            encoding = New UTF8Encoding()
            arrRequest = encoding.GetBytes(UrlString.ToString)
            objRequest.ContentLength = arrRequest.Length
            strmRequest = objRequest.GetRequestStream()
            strmRequest.Write(arrRequest, 0, arrRequest.Length)
            strmRequest.Close()
0
 

Author Comment

by:digitaldaku
ID: 9783640
Sorry missed the point..... The above request is not transferring the web page to asp page.

0
 
LVL 19

Expert Comment

by:cheekycj
ID: 9784374
you are doing a post.

Where is the redirect?

CJ
0
 

Author Comment

by:digitaldaku
ID: 9784943
Many thanks CJ you are the only hope for me to come out of this deep ocean of problem somehow I am stuck and feel like lost.

if I will do the redirect using response.redirect I lose all the values of the HTTP Post or should I do the redirect after execute the above code... I think that will be another request and I know I will lose all the POST values.

Please advice how should achieve the above goal..... I have to pass values from a .aspx page to a .asp page.

Once again thanks...

AB

0
 
LVL 19

Accepted Solution

by:
cheekycj earned 125 total points
ID: 9786828
yes if you do a redirect you use all the post values.  Do you need them again?

Put your redirect after your above code so the flow will be, you post to the asp page and then it redirects after the post.

If you want to maintain the post values you may have to store them somewhere (cookies/url/session) to persist the values.

CJ
0
 

Author Comment

by:digitaldaku
ID: 9822197
Many thanks.

After all those tries I have reverted back in using URL based get method.

Thanks for your efforts.

AB
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11432220
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: cheekycj {http:#9786828}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

pinaldave
EE Cleanup Volunteer
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

691 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