0

Really having trouble trying to implement this in my controller. Essentially as it stands I have a controller than when it completes passes the user to a URL as below:

    <HttpPost()>
    Function Create(job As Job) As ActionResult
        If ModelState.IsValid Then
            db.Jobs.Add(job)
            db.SaveChanges()
            Dim url As String = "/RequestedService/AddService/" + job.JobId.ToString()
            Return Redirect(url)
        End If

        Return View(job)
    End Function

However I am trying to implement the functionality to send an SMS each time this controller is called and have got this working with a URL like (made up without username or password): http://go.bulksms.com:1557/send?username=fred&message=hello This needs to be accessed via an HTTP post request. I understand I can return this URL in the 'Return Redirect' above but I want both to happen (the redirect and the post on this link sending the SMS) and ideally I want the user to be redirected to the page as it happens now but the SMS to be sent in the background. How would I implement this?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
NickP
  • 1,354
  • 1
  • 21
  • 51
  • The most that you can do, it's making an ajax called from your client and return in your actions a `JavascriptResult` and then in the success method do another ajax type post with url of the action and the parameters that you need to pass – Jorge Aug 13 '12 at 19:07

2 Answers2

1

Try this. New code is added between two comment line. You can also consult this url for details, if it's a POST you might have to pass some form data, it's all described in the link above.:

<HttpPost()>
    Function Create(job As Job) As ActionResult
        If ModelState.IsValid Then
            db.Jobs.Add(job)
            db.SaveChanges()
            'Sending SMS here: (start)
            Dim request as WebRequest = WebRequest.Create("http://go.bulksms.com:1557/send?username=fred&message=hello")
            request.Method = "POST"
            Dim response As WebResponse = request.GetResponse()

            'end
            Dim url As String = "/RequestedService/AddService/" + job.JobId.ToString()
            Return Redirect(url)
        End If

        Return View(job)
    End Function
nuhusky2003
  • 366
  • 2
  • 10
0

Redirect is always a GET request

for posting to the different URL , You need to call it from your code using HttpWebRequest class.

Shyju
  • 214,206
  • 104
  • 411
  • 497
  • Ah thanks for the heads up on the GET. How exactly do I call it using HttpWebRequest, I am not quite sure how this would happen in my code as I have tried using intellisense to find HttpWebRequest but no luck (sorry I am fairly novice to ASP) – NickP Aug 13 '12 at 19:07