Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • mayank 1 post 71 karma points
    Nov 29, 2016 @ 23:31
    mayank
    0

    Adding http request

    I am a new user of umbraco but i really need this solution. I have a form, it is sending email to me, all fields, But now i need to send email to me also the same data i have to send to third party url,

    What can i do?

    Using these ideas but not working?

    string url = "3rd Party Url";

    StringBuilder postData = new StringBuilder();

    postData.Append("firstname=" + HttpUtility.UrlEncode(txtFirstName.Text) + "&"); postData.Append("lastname=" + HttpUtility.UrlEncode(txtLastName.Text));

    //ETC for all Form Elements

    // Now to Send Data. StreamWriter writer = null;

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = postData.ToString().Length; try { writer = new StreamWriter(request.GetRequestStream()); writer.Write(postData.ToString()); } finally { if (writer != null) writer.Close(); }

    Response.Redirect("NewPage");

  • raibow 10 posts 80 karma points
    Dec 02, 2016 @ 13:37
    raibow
    0

    Http requests have nothing in common with Umbraco or any other stuff. I suppose you have some controller and you're trying to send this POST request right there. You can do it this way:

    using (var client = new HttpClient())
    {
        var values = new Dictionary<string, string>
        {
           { "key1", "value1" },
           { "key2", "value2" }
        };
    
        var encodedContent = new FormUrlEncodedContent(values);
        var response = await client.PostAsync(url, encodedContent);
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies