2009-11-18 32 views
0

我一直在爲此掙扎三天,我想對第三方提供商進行手動發佈,然後從網絡用戶那裏獲取詳細信息(在這種情況下,提供商是PayFast),然後根據成功或失敗將重定向回我的網站。完成POST並重定向到第三方網站

我已經使用許多在此網站實施例等包括一個手動重新創建形式可以在(http://www.jigar.net/articles/viewhtmlcontent78.aspx),我發現類似於後在計算器問題的主要的例子可以看出試圖1167067

這裏是結果在我的代碼,其接縫處創建流,但我無法弄清楚如何發送控制到供應商的網站,因爲Response.Redirect的殺死流

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 
+1

「將控件發送給提供商網站」是什麼意思? 「WebReq.GetResponse()」行已經將數據發佈到其他網站。 – David

+0

瀏覽器沒有被髮送到網站,如果這是WebReq.GetResponse()應該這樣做,它不起作用。 所以,這就是我的瀏覽器被重定向到PF_HOST,如果我做了Response.Redirect(PF_HOST),那麼它重定向,但沒有形式變量 – WASSA

+0

供參考 const string PF_HOST =「https:// sandbox .payfast.co.za /主機/處理「; – WASSA

回答

0

解決它,這要歸功於http://www.jigar.net/articles/viewhtmlcontent78.aspx

我創建了一個新的類按照商務部,並做了一些調整,像初始化個URL作爲聲明的一部分,它的工作原理就像一個魅力,得益於JigJar

我以前這個解決方案中,並給予之上。