473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

HttpWebRequests and Redirect

Hey Guys,

This is really kicking my butt.

It appears that the server is not getting my data that I am posting...

Basically I am posting a little XML and getting back a response as to
whether it was accepted or not.
I am getting:

System.Xml.XmlException
Root element is missing.
at System.Xml.XmlTextReaderImpl.Throw(Exception e) at
....

private void SubmitWebRequest(string aDomain, string aURL)
{
string PostData = "<?xml version='1.0' ?
><orderstatus>Shipped</orderstatus>";
ASCIIEncoding encoding = new ASCIIEncoding();
System.Net.CookieContainer CookieC = new
System.Net.CookieContainer();
Byte[] Data = encoding.GetBytes(PostData);

System.Net.HttpWebRequest LoginReq =

(System.Net.HttpWebRequest)System.Net.WebRequest.C reate(aDomain+aURL);

LoginReq.KeepAlive = false;
LoginReq.Method = "POST";
LoginReq.AllowAutoRedirect = false;
LoginReq.ContentType = "application/x-www-form-
urlencoded";
LoginReq.ContentLength = Data.Length;
LoginReq.CookieContainer = CookieC;

System.IO.Stream SendReq = LoginReq.GetRequestStream();
SendReq.Write(Data, 0, Data.Length);
SendReq.Close();

System.Net.HttpWebResponse LoginRes =
(System.Net.HttpWebResponse)LoginReq.GetResponse() ;
string sRedirect = LoginRes.Headers.Get("Location");
CookieC.Add(LoginRes.Cookies);

LoginReq =
(System.Net.HttpWebRequest)System.Net.WebRequest.C reate(aDomain
+sRedirect);
LoginReq.KeepAlive = false;
LoginReq.Method = "GET";
LoginReq.ContentType = "application/x-www-form-
urlencoded";
LoginReq.AllowAutoRedirect = true;
LoginReq.CookieContainer = CookieC;

LoginRes =
(System.Net.HttpWebResponse)LoginReq.GetResponse() ;
StreamReader sReader = new
StreamReader(LoginRes.GetResponseStream());
string HTML = sReader.ReadToEnd();
System.Windows.Forms.MessageBox.Show(HTML);
}

Any help would be MUCH appreciated!

GINA_M

May 17 '07 #1
5 11305
Should mention that the web app is using URL based session, so the
first request (that doesn't have a session yet) is answered with a
redirect with the session in the url.

Gina_M

May 18 '07 #2
Should mention that the web app is using URL based session, so the
first request (that doesn't have a session yet) is answered with a
redirect with the session in the url.

Gina_M

May 18 '07 #3
Hi,
If i don't remember bad, you should write a new line between the <xml>
node and the root.
Something like this:

string PostData = "<?xml version='1.0' ?>" + Environment.NewLine +
"<orderstatus>Shipped</orderstatus>";

Good luck!,
Diego

May 18 '07 #4
Thanks Deigo.

99.9% of the solutions out there handle the redirect incorrectly, at
least for my purposes.

Here is the solution that works great.

http://www.codeproject.com/cs/intern...t_response.asp

ONE NOTE: the link assumes that the redirect URL returned is the full
URL and that is not always the case.

I added:

if (!ReUri.StartsWith("http:/", true, null))
ReUri = _Domain + ReUri;

Where the domain is the base server name. You must also add check for
"/" to make sure that you format your reUri correctly.

Gina_M
May 18 '07 #5

and what about https:// ?

:-)

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On 18 May 2007 09:17:46 -0700, Gina_Marano <gi*******@gmail.com>
wrote:
>Thanks Deigo.

99.9% of the solutions out there handle the redirect incorrectly, at
least for my purposes.

Here is the solution that works great.

http://www.codeproject.com/cs/intern...t_response.asp

ONE NOTE: the link assumes that the redirect URL returned is the full
URL and that is not always the case.

I added:

if (!ReUri.StartsWith("http:/", true, null))
ReUri = _Domain + ReUri;

Where the domain is the base server name. You must also add check for
"/" to make sure that you format your reUri correctly.

Gina_M
May 18 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bob Garbados | last post by:
forgive my ignorance, as I'm new to php coming from a ms background... If I create a page named redirect.php and it's only content is: <?php header("Location: http://www.google.com"); ?>...
5
by: Steve Lutz | last post by:
Hello, I have a page that creates a class, and then on certain conditions, redirects user to another page. The class has a Class_Terminate() function that saves itself to a database. The class...
3
by: Paul | last post by:
I'm not getting the results I want when I use Response.Redirct in a ASP page. I enter this line of code in a asp page from domain1.com. Response.Redirect...
7
by: Donna Hawkins | last post by:
I want to use javascript to redirect to a URL which has been passed as a variable (in php). I have searched but cannot find any solution. I think this code is a basic redirect: <script...
3
by: Justin | last post by:
Hi, Im confused here over the usage of Response.Redirect and Server.Transfer. I used frameset for my work, what are the proper usages of the two methods that seems working similar.. The...
6
by: Peter Row | last post by:
Hi, I am writing a DLL in VB.NET that implements IHttpHandler.ProcessRequest. This code calls a sub and I need to know if that sub did a response redirect or not. Specifically I need to know...
7
by: djc | last post by:
I see many ways to accomplish setting up proxy settings for a web request in the documentation but many of them are marked as obsolete. 1) What is the current and correct way to tell all my...
5
by: venner | last post by:
I'm having an issue with an ASP.NET website after upgrading to ASP.NET 2.0. The website makes use of a central authentication service (CAS) provided at the university I work for. Each page checks...
10
by: Eirik Eldorsen | last post by:
How can I 301 redirect www.example.com/default.aspx to www.example.com without using ISAPI filters?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.