-1

I'm trying to call an Azure Automation Runbook from a simple ASP.NET website, to call this runbook I have to make a simple HTTP POST from my website. My idea is to create a simple button that onclick sends this HTTP request.

How can I do this?

BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

0

In your simple website, put an ASP button on your ASPX page (with runat="server" so it does the callback to your server).

<asp:Button ID="Submit" runat="server" Text="Submit" />

and put your code in the button's call back procedure in your callback code (legacy style .aspx.vb in this example) to send the post to a different site.

Protected Sub Submit_Click(sender As Object, e As EventArgs) Handles Submit.Click

'Build the post data string to send
    Dim PostData As String
    PostData = PostData & "YourValueName1=" & System.Web.HttpUtility.UrlEncode(YourValuetoSend1) & "&" 
    PostData = PostData & "YourValueName2=" & System.Web.HttpUtility.UrlEncode(YourValuetoSend2)

'Convert the string to byte array for posting
    Dim enc As New System.Text.UTF8Encoding
    Dim postdatabytes As Byte()
    postdatabytes = enc.GetBytes(PostData)


'send it
    Dim web As System.Net.HttpWebRequest
    web = System.Net.WebRequest.Create("http://www.Your_Azure_Site_to_Post_To.com/subdirectory/pagename.aspx")
    web.Method = "POST"
    web.ContentType = "application/x-www-form-urlencoded"

    web.ContentLength = postdatabytes.Length

    Using stream = web.GetRequestStream()
        stream.Write(postdatabytes, 0, postdatabytes.Length)
        stream.Close()
    End Using

    Dim result As System.Net.WebResponse
    result = web.GetResponse()
End Sub
John Price
  • 166
  • 1
  • 5