2

我想从服务器端(ASP.NET/C#)发布此表单:

<FORM action="https://login:password@payment.architrade.com/cgi-adm/refund.cgi" method=POST>
    <input type="hidden" name="merchant" value="12345678">
    <input type="hidden" name="transact" value="11111111">
    <input type="hidden" name="amount" value="2000">
    <input type="hidden" name="currency" value="208">
    <input type="hidden" name="orderid" value="11223344">
    <input type="hidden" name="md5key" value="cfcd208495d565ef66e7dff9f98764da">
    <input type="hidden" name="textreply" value="yes">
</FORM>

我正在尝试使用 WebClient.UploadValues。我的代码是

 private void PostRefundRequest(Mediachase.Commerce.Orders.Payment payment)
    {
        WebClient webClient = new WebClient();
        NameValueCollection refundRequest = new NameValueCollection();
        PaymentMethodDto dibs = PaymentManager.GetPaymentMethodBySystemName("DIBS", SiteContext.Current.LanguageName);
        string merchant = GetParameterByName(dibs, DIBSPaymentGateway.UserParameter).Value;
        PurchaseOrder po = payment.Parent.Parent as PurchaseOrder;
        string orderid = po.TrackingNumber;
        string transact = payment.TransactionID;
        string amount = (payment.Amount * 100).ToString();
        refundRequest.Add("merchant", merchant);
        refundRequest.Add("transact", transact);
        refundRequest.Add("amount", amount );

        refundRequest.Add("currency", payment.Parent.Parent.BillingCurrency);
        refundRequest.Add("orderid", orderid);
        string md5 = GetMD5KeyRefund(merchant, orderid, transact, amount);
        refundRequest.Add("md5key", md5);
        refundRequest.Add("textreply", "yes");
        byte[] responseArray = webClient.UploadValues("https://<mylogin>:<mypassword>@payment.architrade.com/cgi-adm/refund.cgi", refundRequest);
    }

我尝试调试,一切似乎都正确,但 API 返回 HTTP 401(未经授权)。我关心的是:WebClient.UploadValues 是否支持 API 的 url(包括用户名/密码)

谢谢你。

4

2 回答 2

3

你必须有 UploadValues 的 Post in 方法参数:

NameValueCollection data = new NameValueCollection();
data["input-data1"] = "value1";
data["input-data2"] = "value2";
data["input-data3"] = "value3";

WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential(mylogin, mypassword);
byte[] responseBytes = webClient.UploadValues("http://www.example.com/posttome.aspx", "POST", data);
string response = Encoding.UTF8.GetString(responseBytes);

更新:也许这还不够,因为在文档中指出 POST 是 http 方案的默认设置(http://msdn.microsoft.com/en-us/library/9w7b4fz7.aspx)我认为这对于 https 是一样的

更新 2:出于安全原因,Microsoft 在 Internet Explorer ( http://support.microsoft.com/kb/834489 ) 的 URL 中禁用了该身份验证,因此 Web 客户端可能禁用了该身份验证

于 2012-04-19T11:07:21.480 回答
-4

只需为表单提供一个 ID 并使用以下代码提交

 $('#formid').submit();
于 2012-04-19T07:52:10.543 回答