MikeCombe
asked on
HTTPPOST - sending via ASP works, sending via ASPX does NOT work
Using ASP I can send send a string using HTTPPOST & get an expected response.
Using ASPX I do NOT get an expected response.
It appears that the ASPX is NOT sending the string.
QUESTION: What am I doing wrong in the ASPX webpage
'------------------------- ---------- ---------- ----------
' test_httppost_send.asp <--- works as expected
'------------------------- ---------- ---------- ----------
color = "red"
strMsg = "color=" & color
myURL = "http://www.someurl.com/test_httppost_receive.asp"
set xmlhttp = createobject("msxml2.serve rxmlhttp")
xmlhttp.Open "POST", myURL, false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-ur lencoded"
xmlhttp.Send (strMsg)
strResponse = xmlhttp.responseText
set xmlhttp = nothing
Response.Write strResponse
'------------------------- ---------- ---------- ----------
'------------------------- ---------- ---------- ----------
' test_httppost_send.aspx <--- does NOT work as expected
'------------------------- ---------- ---------- ----------
dim color as string = "red"
dim strMsg as string = ""
dim myURL as string = "http://www.someurl.com/test_httppost_receive.asp"
dim myResponse as string = ""
strMsg = "color=" & color
dim xmlhttp = Server.CreateObject("msxml 2.serverxm lhttp")
xmlhttp.Open ("POST", myURL, false)
xmlhttp.setRequestHeader ("Content-Type","applicati on/x-www-f orm-urlenc oded")
xmlhttp.Send (strMsg)
myResponse = xmlhttp.responseText
xmlhttp=nothing
Response.Write (myResponse)
'------------------------- ---------- ---------- ----------
'------------------------- ---------- ---------- ----------
' test_httppost_receive.asp <--- echo back the string posted
'------------------------- ---------- ---------- ----------
Sender_color = Request.Form("color")
Response.Write "Sender_color = " & Sender_color
'------------------------- ---------- ---------- ----------
Using ASPX I do NOT get an expected response.
It appears that the ASPX is NOT sending the string.
QUESTION: What am I doing wrong in the ASPX webpage
'-------------------------
' test_httppost_send.asp <--- works as expected
'-------------------------
color = "red"
strMsg = "color=" & color
myURL = "http://www.someurl.com/test_httppost_receive.asp"
set xmlhttp = createobject("msxml2.serve
xmlhttp.Open "POST", myURL, false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-ur
xmlhttp.Send (strMsg)
strResponse = xmlhttp.responseText
set xmlhttp = nothing
Response.Write strResponse
'-------------------------
'-------------------------
' test_httppost_send.aspx <--- does NOT work as expected
'-------------------------
dim color as string = "red"
dim strMsg as string = ""
dim myURL as string = "http://www.someurl.com/test_httppost_receive.asp"
dim myResponse as string = ""
strMsg = "color=" & color
dim xmlhttp = Server.CreateObject("msxml
xmlhttp.Open ("POST", myURL, false)
xmlhttp.setRequestHeader ("Content-Type","applicati
xmlhttp.Send (strMsg)
myResponse = xmlhttp.responseText
xmlhttp=nothing
Response.Write (myResponse)
'-------------------------
'-------------------------
' test_httppost_receive.asp <--- echo back the string posted
'-------------------------
Sender_color = Request.Form("color")
Response.Write "Sender_color = " & Sender_color
'-------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please use these imports on your aspx.vb page:
Imports System.Net
Imports System.IO
You could use naming convention that meets your requirement, code sample provided is to guide you in correct direction.
Imports System.Net
Imports System.IO
You could use naming convention that meets your requirement, code sample provided is to guide you in correct direction.
ASKER
already have these imports:
Imports System.Net
Imports System.IO
Imports System.Net
Imports System.IO
Could you please provide more details on error received on page.
ASKER
Here's the error page:
Server Error in '/myPath' Application.
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
The remote server returned an error: (500) Internal Server Error.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
Source Error:
Line 681: dataStream.Close()
Line 682:
Line 683: Dim WebResponse1 As WebResponse = objXML.GetResponse()
Line 684: dataStream = WebResponse1.GetResponseSt ream()
Line 685:
Source File: myPath\myDoc.aspx Line: 683
Stack Trace:
[WebException: The remote server returned an error: (500) Internal Server Error.]
System.Net.HttpWebRequest. GetRespons e() +5375997
ASP.datatransfer_myPath_my Doc_aspx._ _Render__c ontrol1(Ht mlTextWrit er __w, Control parameterContainer) in c:\path\myDoc.aspx:683
System.Web.UI.Control.Rend erChildren Internal(H tmlTextWri ter writer, ICollection children) +256
System.Web.UI.Control.Rend erChildren (HtmlTextW riter writer) +19
System.Web.UI.Page.Render( HtmlTextWr iter writer) +29
System.Web.UI.Control.Rend erControlI nternal(Ht mlTextWrit er writer, ControlAdapter adapter) +27
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer, ControlAdapter adapter) +99
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer) +25
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +1266
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618
Server Error in '/myPath' Application.
--------------------------
The remote server returned an error: (500) Internal Server Error.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
Source Error:
Line 681: dataStream.Close()
Line 682:
Line 683: Dim WebResponse1 As WebResponse = objXML.GetResponse()
Line 684: dataStream = WebResponse1.GetResponseSt
Line 685:
Source File: myPath\myDoc.aspx Line: 683
Stack Trace:
[WebException: The remote server returned an error: (500) Internal Server Error.]
System.Net.HttpWebRequest.
ASP.datatransfer_myPath_my
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Page.Render(
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Page.Process
--------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618
Please see attached code, have tested and is working fine on test environment.
In the ZIP file attached rename "test_httppost_receive.asp .txt" to "test_httppost_receive.asp ".
Also if the error still persists have a look at this link
http://forums.asp.net/t/1693667.aspx/1?The+remote+server+returned+an+error+500+Internal+Server+Error
HTTPRequest-.zip
In the ZIP file attached rename "test_httppost_receive.asp
Also if the error still persists have a look at this link
http://forums.asp.net/t/1693667.aspx/1?The+remote+server+returned+an+error+500+Internal+Server+Error
HTTPRequest-.zip
ASKER
The code in the accepted solution worked fine in the test environment. So, that's good. It is a great, clear example of making an HTTPPOST request using ASPX or VB.net.
The error that I referred to (08/08/11 10:05 AM, ID: 36330102) occured when I used that code in a production environment. The error: (500) Internal Server Error....is probably due to another issue.
Thanks for your help on providing a great ASPX example.
The error that I referred to (08/08/11 10:05 AM, ID: 36330102) occured when I used that code in a production environment. The error: (500) Internal Server Error....is probably due to another issue.
Thanks for your help on providing a great ASPX example.
ASKER
The remote server returned an error: (500) Internal Server Error.
on this line:
Dim response As WebResponse = objXML.GetResponse()
Also, why would someone use the word "response" as an object?
That eliminates the use of Response.Write ("blah, blah")
Wouldn't a better object name be something like "WebResponse1" ?