2

I want to post this form from server side (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>

I'm trying to use WebClient.UploadValues. My code is

 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);
    }

I tried to debug, and everything seems to be correct, but the API returns HTTP 401 (Unauthorized). My concern is: does WebClient.UploadValues support the url of the API (which includes username/password)

Thank you.

Delta76
  • 13,931
  • 30
  • 95
  • 128

2 Answers2

3

You got to have Post in method parameter for UploadValues :

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);

Update: Maybe this is not enough, because in documentation is stated that POST is default for http scheme (http://msdn.microsoft.com/en-us/library/9w7b4fz7.aspx) I presume that is the same for https

Update 2: Microsoft disabled that authentication in URL for internet explorer (http://support.microsoft.com/kb/834489) for security reasons, so probably that is disabled for web client to

hogarth45
  • 3,387
  • 1
  • 22
  • 27
Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
-4

Just give an Id to the form and submit using the bellow code

 $('#formid').submit();
Thiliban
  • 74
  • 4
  • This would work if the question was related to `client side` and `jQuery`, but it's `server-side` Vimvq is interested in. – Richard Apr 19 '12 at 08:14
  • @Vimvq1987 is this link use full? http://stackoverflow.com/questions/1539685/how-programmatically-submit-a-form-without-a-submit-button-in-webbrowser – Thiliban Apr 19 '12 at 08:24