我正試圖在剃鬚刀中使用mvc4進行支付網關集成。在這一點上,我需要用預填寫的表單來調用頁面。使用MVC 4中的POST參數重定向支付網關集成
使用下面的方法,我形成了POST方法形式:
private static string PreparePOSTForm(string url, System.Collections.Hashtable data) // post form
{
//Set a name for the form
string formID = "PostForm";
//Build the form using the specified data to be posted.
StringBuilder strForm = new StringBuilder();
strForm.Append("<form id=\"" + formID + "\" name=\"" +
formID + "\" action=\"" + url +
"\" method=\"POST\">");
foreach (System.Collections.DictionaryEntry key in data)
{
strForm.Append("<input type=\"hidden\" name=\"" + key.Key +
"\" value=\"" + key.Value + "\">");
}
strForm.Append("</form>");
//Build the JavaScript which will do the Posting operation.
StringBuilder strScript = new StringBuilder();
strScript.Append("<script language='javascript'>");
strScript.Append("var v" + formID + " = document." +
formID + ";");
strScript.Append("v" + formID + ".submit();");
strScript.Append("</script>");
//Return the form and the script concatenated.
//(The order is important, Form then JavaScript)
return strForm.ToString() + strScript.ToString();
}
而在我的控制頁面我與所需的參數調用PreparePostForm
和我收到的POST請求的格式。
[HttpPost]
public ActionResult OrderSummary()
{
string request=PreparePOSTForm("payment URL","hashdata required for payment")
return Redirect(request);
}
但是,雖然重定向我越來越低於錯誤。
錯誤的請求 - 無效的URL
HTTP 400錯誤的請求URL無效。
我錯過了這裏使用POST請求的東西。有人能幫我嗎。
在此先感謝。
很簡單明瞭。謝謝! –