tags:

views:

160

answers:

1

I have been struggling with this for three days, I want to do a manual post to a third party provider, that will then take details from the web user (in this case the provider is PayFast) and then will redirect back to my site depending on the success or failure.

I have tried using a number of examples on this site and others including one that manually recreates the form as can be seen at (http://www.jigar.net/articles/viewhtmlcontent78.aspx) the main example that I find is similar to the post at stackoverflow questions 1167067

here is the result in my code, which seams to create the stream, but I cannot figure out how to send the control to the providers website since response.redirect kills the stream

string vystup = null;
//Our postvars
byte[] buffer = Encoding.ASCII.GetBytes(pPostData);
//Initialisation, we use localhost, change if appliable
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(PF_HOST);
//Our method is post, otherwise the buffer (postvars) would be useless
WebReq.Method = "POST";
//We use form contentType, for the postvars.
WebReq.ContentType = "application/x-www-form-urlencoded";
//The length of the buffer (postvars) is used as contentlength.
WebReq.ContentLength = buffer.Length;
//We open a stream for writing the postvars
Stream PostData = WebReq.GetRequestStream();
//Now we write, and afterwards, we close. Closing is always important!
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
//Get the response handle, we have no true response yet!
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
//Let's show some information about the response
PostResult = "=Status Code: " + WebResp.StatusCode ;
Console.WriteLine(WebResp.Server);

//Now, we read the response (the string), and output it.
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
vystup = _Answer.ReadToEnd();

PostResult = "redirect called...";

// Need to now send the post form to PayFast
A: 

Solved it,thanks to http://www.jigar.net/articles/viewhtmlcontent78.aspx%20

I created a new class as per the doc, and made a few tweaks, like initializing th URL as part of the declaration and it works like a charm, thanks to JigJar

I had found this solution before, and given up on it.

WASSA