gpt4 book ai didi

post - Chrome/Safari POST 问题

转载 作者:太空宇宙 更新时间:2023-11-03 16:12:10 26 4
gpt4 key购买 nike

我在 .Net 中编写了一个小型购物车,它会在订单完成后派人到 PayPal 进行付款。为了将它们发送到 PayPal,我在一个通用的“paypal.aspx”页面上有以下表格,该页面上没有真正的用户功能:

<form action="http://www.paypal.com/cgi-bin/webscr" method="post" id="paypal">
<input type="hidden" name="cmd" value="_cart"/>
<input type="hidden" name="upload" value="1"/>
<input type="hidden" name="business" value="email@email.com"/>
<input type="hidden" name="tax_cart" id="tax_cart" />
<input type="hidden" name="handling_cart" id="handling_cart" />
<input type="hidden" name="return" id="return" value='<%="http://" + Request.Url.Authority + "/" %>' />
<input type="hidden" name="custom" id="custom" />
<input type="hidden" name="first_name" id="first_name" />
<input type="hidden" name="last_name" id="last_name" />
<input type="hidden" name="address1" id="address1" />
<input type="hidden" name="address2" id="address2" />
<input type="hidden" name="city" id="city" />
<input type="hidden" name="state" id="state" />
<input type="hidden" name="zip" id="zip" />
<input type="submit" id="paypalButton" value="PayPal" style="display: none; visibility: hidden;"/>
</form>

当包含此表单的页面加载时,在其正下方有另一个表单,其中包含一堆隐藏字段,这些字段填充了来自实际订单的数据(根据 Guid 查询字符串值提取)。该表单中的 JavaScript 会像这样填写 PayPal 需要的值:

    <form runat="server">
<asp:ScriptManager runat="server" />
<div id="ppItems">
<asp:Repeater runat="server" ID="rpItems">
<ItemTemplate>
<input type="hidden" id='<%#"hv_quantity_" + Container.ItemIndex %>' value='<%#Eval("Quantity") %>' />
<input type="hidden" id='<%#"hv_item_" + Container.ItemIndex %>' value='<%#Eval("Color") + " Tactical Hat" %>' />
<input type="hidden" id='<%#"hv_amount_" + Container.ItemIndex %>' value='<%#Eval("UnitCost", "{0:n2}") %>' />
</ItemTemplate>
</asp:Repeater>
</div>

<asp:HiddenField runat="server" ID="hvCustom" />
<asp:HiddenField runat="server" ID="hvTax" />
<asp:HiddenField runat="server" ID="hvShipping" />
<asp:HiddenField runat="server" ID="hvFirstName" />
<asp:HiddenField runat="server" ID="hvLastName" />
<asp:HiddenField runat="server" ID="hvAddress1" />
<asp:HiddenField runat="server" ID="hvAddress2" />
<asp:HiddenField runat="server" ID="hvCity" />
<asp:HiddenField runat="server" ID="hvState" />
<asp:HiddenField runat="server" ID="hvZip" />

<script type="text/javascript" language="javascript">
var paypal = document.getElementById('paypal');

function load() {
Sys.Application.remove_load(load);

//set the items
var ppItems = document.getElementById('ppItems');
var items = ppItems.getElementsByTagName('input');
var itemsCount = items.length / 3;

for (var i = 0; i < itemsCount; ++i) {
var quantity = document.getElementById('hv_quantity_' + i).value;
var item = document.getElementById('hv_item_' + i).value;
var amount = document.getElementById('hv_amount_' + i).value;

addFormItem('item_name_' + (i + 1), quantity + " " + item);
addFormItem('amount_' + (i + 1), amount);
addFormItem('quantity_' + (i + 1), quantity);
}

//set global items
var custom = document.getElementById('<%=this.hvCustom.ClientID %>').value;
document.getElementById('tax_cart').value = document.getElementById('<%=hvTax.ClientID %>').value;
document.getElementById('handling_cart').value = document.getElementById('<%=this.hvShipping.ClientID %>').value;
document.getElementById('return').value += 'thanks.aspx?p=' + custom;
document.getElementById('custom').value = custom;
document.getElementById('first_name').value = document.getElementById('<%=this.hvFirstName.ClientID %>').value;
document.getElementById('last_name').value = document.getElementById('<%=this.hvLastName.ClientID %>').value;
document.getElementById('address1').value = document.getElementById('<%=this.hvAddress1.ClientID %>').value;
document.getElementById('address2').value = document.getElementById('<%=this.hvAddress2.ClientID %>').value;
document.getElementById('city').value = document.getElementById('<%=this.hvCity.ClientID %>').value;
document.getElementById('state').value = document.getElementById('<%=this.hvState.ClientID %>').value;
document.getElementById('zip').value = document.getElementById('<%=this.hvZip.ClientID %>').value;

//submit to paypal
document.getElementById('paypalButton').click();
}

function addFormItem(name, value) {
var item = document.createElement('input');
item.setAttribute('type', 'hidden');
item.setAttribute('name', name);
item.setAttribute('id', name);
item.setAttribute('value', value);

paypal.appendChild(item);
}

Sys.Application.add_load(load);

</script>

所以当整个页面加载时,订单详细信息根据查询字符串 guid 值从数据库中提取,一堆隐藏字段填充数据库中的所需值,然后上面的脚本在加载时运行设置 PayPal形成值,然后单击隐藏按钮将所有内容提交给 PayPal,以便最终用户付款。

我遇到的问题是这在 IE7+ 和 FF3+ 中运行良好,但 Safari 和 Chrome 运行不佳。在 Chrome 中,我被重定向到 PayPal 主页,而不是被要求付款。 Safari 甚至更奇怪,因为它们都重定向到 PayPal 支付屏幕(如 IE7+ 和 FF3+),但仅在 Mac 版本上它不会预填充所有字段(特别是名称/地址),但其他字段(如金额、税收等)做填充。

谁能就为什么 Chrome 和 Safari(仅限 Mac)无法正常工作,而其他一切似乎都可以提供任何建议?

最佳答案

我终于通过走老路并重定向而不是执行 POST 弄明白了:

var order = (from o in data.Orders where o.PayPal == Request.QueryString["p"] select o).Single();

//build the generic PP detail
sb.Append("http://www.paypal.com/cgi-bin/webscr/?cmd=_cart");
sb.AppendValue("upload", "1", false);
sb.AppendValue("business", "email@domain.com", true);
sb.AppendValue("handling_cart", (this.CurrentCart.Tax.HasValue ? this.CurrentCart.Tax.ToString() : "0"), false);
sb.AppendValue("return", this.Request.Url.Authority, true);
sb.AppendValue("custom", order.PayPal, true);
sb.AppendValue("first_name", (order.Customer.Name.IndexOf(" ") > -1) ? order.Customer.Name.Split(' ')[0] : order.Customer.Name, true);
sb.AppendValue("last_name", (order.Customer.Name.IndexOf(" ") > -1) ? order.Customer.Name.Split(' ')[1] : order.Customer.Name, true);
sb.AppendValue("address1", order.Customer.Address1, true);
sb.AppendValue("address2", order.Customer.Address2, true);
sb.AppendValue("city", order.Customer.City, true);
sb.AppendValue("state", order.Customer.StateProvince, true);
sb.AppendValue("zip", order.Customer.PostalCode, true);

for (int i = 0; i < order.OrderItems.Count; ++i)
{
string index = (i + 1).ToString();
sb.AppendValue("item_name_" + index, order.OrderItems[i].ProductAttribute.Name, true);
sb.AppendValue("amount_" + index, string.Format("{0:n2}", order.OrderItems[i].UnitCost), false);
sb.AppendValue("quantity_" + index, order.OrderItems[i].Quantity.ToString(), true);
}

Response.Redirect(sb.ToString());

AppendValue 方法是 StringBuilder 的扩展方法,它看起来像这样:

public static void AppendValue(this StringBuilder sb, string name, string value, bool encode)
{
sb.Append("&" + name + "=" + ((encode) ? HttpUtility.UrlEncode(value) : value));
}

关于post - Chrome/Safari POST 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7212005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com