473,379 Members | 1,355 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,379 software developers and data experts.

C# StreamWriter Problem

109 100+
i got a nice problem here:
my page recieves a request, it then sends a request back to the other server with all of the same params as the orignal requess, and waits for a responce the responce should be "Valid" or "Invalid"
and then my pages sends back the orignal response witch is discarded.

When i run on local.host everything works perfectly.
I upload my files to the server, and run the page and it crashes at this line of code:

Expand|Select|Wrap|Line Numbers
  1.         StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
  2.  


the full function is:

Expand|Select|Wrap|Line Numbers
  1.     protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         LogAMessage.logAMessage("1");
  4.         //Post back to either sandbox or live
  5.         string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
  6.         //string strLive = "https://www.paypal.com/cgi-bin/webscr";
  7.         HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
  8.         LogAMessage.logAMessage("2");
  9.         //Set values for the request back
  10.         req.Method = "POST";
  11.         LogAMessage.logAMessage("3");
  12.         req.ContentType = "application/x-www-form-urlencoded";
  13.         LogAMessage.logAMessage("4");
  14.         byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
  15.         LogAMessage.logAMessage("5");
  16.         string strRequest = Encoding.ASCII.GetString(param);
  17.         LogAMessage.logAMessage("6");
  18.         strRequest += "&cmd=_notify-validate";
  19.         LogAMessage.logAMessage("7");
  20.         req.ContentLength = strRequest.Length;
  21.         LogAMessage.logAMessage("8");
  22.  
  23.         //for proxy
  24.         //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
  25.         //req.Proxy = proxy;
  26.  
  27.         //Send the request to PayPal and get the response
  28.         StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
  29.         LogAMessage.logAMessage("9");
  30.         streamOut.Write(strRequest);
  31.         LogAMessage.logAMessage("10");
  32.         streamOut.Close();
  33.         LogAMessage.logAMessage("11");
  34.         StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
  35.         LogAMessage.logAMessage("12");
  36.         string strResponse = streamIn.ReadToEnd();
  37.         LogAMessage.logAMessage("13");
  38.         streamIn.Close();
  39.         LogAMessage.logAMessage("14");
  40.  
  41.         if (strResponse == "VERIFIED")
  42.         {
  43.             LogAMessage.logAMessage("IPN is Verified");
  44.         }
  45.         else if (strResponse == "INVALID")
  46.         {
  47.             LogAMessage.logAMessage("IPN is INVALID");
  48.         }
  49.         else
  50.         {
  51.             LogAMessage.logAMessage("IPN BROKEN");
  52.         }
  53.     }
  54.  
  55.  
the LogAMessage.logAMessage() function is a simple function that writes a message to a text file. My text file gets up to number 8 and then nothing.

Thanks for your help.
Apr 22 '08 #1
10 3166
Plater
7,872 Expert 4TB
I think when you call the RequestStream it does somesort of "pre-call" to the server....maybe?
Apr 22 '08 #2
SpecialKay
109 100+
by "pre-call" you mean?

waiting for reply
Apr 22 '08 #3
Plater
7,872 Expert 4TB
Like when you say get request stream, it sends a partial request to the server "POST /somepage.asp HTTP/1.1" and then when you finish with the stream it sends the rest?
"Content-Length: 10

asdfghjklq"
Apr 22 '08 #4
SpecialKay
109 100+
doesnt sound right,
do you have any suggestion on how i can fix it?
Apr 23 '08 #5
Plater
7,872 Expert 4TB
Hmm, I'm starting to doubt my original guess at the problem.
What exception is thrown?
Apr 23 '08 #6
SpecialKay
109 100+
Absolutly NOTHING, code just stops. No exceptions at all, and it doesnt not go into the Finally()
Apr 23 '08 #7
SpecialKay
109 100+
OOps sorry, i have now put the code into a try()catch()finally() and i have tried to catch all possible exceptions with no luck, and the finally doesnt not get called either. The code just stops.

My theory for now is simply that my server is blocking the out going request.
Apr 23 '08 #8
SpecialKay
109 100+
Update to problem
execption thrown = Unable to connect to remote server
Apr 23 '08 #9
Plater
7,872 Expert 4TB
Ah ha, well that's where you need to fix, why it cannot connect to server.
Is the URL being passed to it correct?
Apr 23 '08 #10
SpecialKay
109 100+
Answer: Firewall problem.
Apr 23 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob Hansen | last post by:
I am having a very strange problem with StreamWriter and writing to files. I have a procedure that is called several times to write out seperate files, each of them uniquely named by date all they...
1
by: Lars Hansen | last post by:
Hi This is probably pretty basic, but I have a problem with the access-level (local variable), when creating a new StreamWriter. I am trying to write some price information to a textfile - which...
13
by: Rob Corwin | last post by:
Hi, a c# app of mine that parses 30,000 xml files writes large amounts of data to file (> 2GB) using a streamwriter object (sw). everything works fine except that the memory used by the app grows...
5
by: Rob Corwin | last post by:
Hi, a c# app of mine that parses 30,000 xml files writes large amounts of data to flat file (> 2GB) using a streamwriter object (sw). everything works fine except that the memory used by the app...
5
by: Brendan Miller | last post by:
Hi, I have been having a problem writing the contents of a dataset to a .csv file. When I write to a .csv file and open it with either Excel or Wordpad the "french" characters are wrong. When I...
9
by: ShadowOfTheBeast | last post by:
Hi, I have got a major headache understanding streamReader and streamWriter relationship. I know how to use the streamreader and streamwriter independently. but how do you write out using the...
10
by: Oscar Thornell | last post by:
Hi, I generate and temporary saves a text file to disk. Later I upload this file to Microsoft MapPoint (not so important). The file needs to be in UTF-8 encoding and I explicitly use the...
5
by: ramendra | last post by:
Hello there, I am having some problem with using StreamWriter object in aspnet application. The thing is when i use the streamwriter in an aspnet page the code gets executed fine but its...
2
by: gordon | last post by:
Hi, I am trying to create a reference to an external file to write to using stream writer and a value that is created in a for. Basically the value that a user will create will be the name...
4
by: Heron | last post by:
Hi, Could someone explain me why the following code doesn't work? The memorystream always remains with length 0. MemoryStream input = new MemoryStream();
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.