2016-07-13 14 views
0

Ques:リダイレクトや別のページを使用せずに投稿したページと同じページで応答を取得します。同じ方法でPostメソッドを使用したリクエストとレスポンスWebフォーム

ダイナミックウェブフォームを作成しました。

<form id="PostForm" name="PostForm" action="https://merchant.PaymentGateway.com/thirdparties/doubleverification.htm" method="POST"> 
    <input type="hidden" name="merchant_code" value="XYZ"> 
    <input type="hidden" name="encdata" value="+yw5GSwy5ns7XP0/XYZ/6YEkdfjs fjvnsdr+cecGpm0kwhgopO3Jc9RHTld+sj7h6EKm5tcFGN8/oc5yG9E2JfXeboxlkw31bkrD4fXFr0="> 
</form> 

私は投稿をリクエストしています。このHTMLコードの一部を別のページにリダイレクトせずにC#を使用してリクエストしてください。

私はこれを以下のコードを使用しようとしましたが、クエリ文字列の値は正しくありません。

public bool SendSMS(string mobileNo, string message) 
    { 
     try 
     { 

      string strUrl = "https://merchant.PaymentGateway.com/thirdparties/doubleverification.htm.......... SO On..."; 
      WebRequest request = HttpWebRequest.Create(strUrl); 
      HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
      Stream s = response.GetResponseStream(); 
      StreamReader readStream = new StreamReader(s); 
      string dataString = readStream.ReadToEnd(); 
      response.Close(); 
      s.Close(); 
      readStream.Close(); 

      return true; 
     } 
     catch (Exception) 
     { 
      return false; 
     } 
    } 

これらはPostメソッドで上記のようにフォームにのみ値が必要です。できるだけ早くご提案ください。

+0

これを削除する必要がありますか? 'action =" https://merchant.PaymentGateway.com/thirdparties/doubleverification.htm " – Sherlock

+0

このサンプルURLの投稿を実行する必要があります。主な問題は、POSTメソッド、クエリ文字列URLだけを受け入れることができないことです。 URLを介してクエリ文字列を試してみると、エラーが表示されます。 しかし、私はどこでURLを削除しなければならないのか、どうしてplsが精巧になるのかを知ることができません。 –

+0

WebRequestはPOSTとして送信できます。 https://msdn.microsoft.com/en-us/library/system.net.webrequest.method(v=vs.110).aspx –

答えて

0

私はこの質問に対して回答を得ました。

protected void Page_Load(object sender, EventArgs e) 
{ 
    string ForChecksum = string.Format("Sbi_txn_id={2}|arn={0}|amount={1}", "08072016012003001", "1", "1234567890"); 
    DoubleVerificationCheck(ForChecksum.Trim()); 
} 

public string DoubleVerificationCheck(string data) 
{ 
    NameValueCollection requestNameValue = new NameValueCollection(); 
    string postData = "encdata=" + data + "|merchant_code=XYZ"; 
    NameValueCollection nameValue = new NameValueCollection(); 
    nameValue.Add("merchant_code", "XYZ"); 
    nameValue.Add("encdata", data); 
    string responseMsg = PostRequest("https://merchant.Payemtgateway.com/doubleverification.htm", nameValue); 
    return responseMsg; 

} 

public static string PostRequest(string uri, NameValueCollection pairs) 
{ 
    byte[] response = null; 
    using (WebClient client = new WebClient()) 
    { 
     response = client.UploadValues(uri, pairs); 
    } 
    return System.Text.Encoding.UTF8.GetString(response); 
} 
関連する問題