locked
Response Redirect (Hidden) RRS feed

  • Question

  • User-2051275383 posted

    Hey guys,

    I have a form that I have users filling out and when they submit, it inserts the data into the database - Obviously all working fine.

    I have an external service that I want to use (SMS gateway) and I don't want users to see what I sent there (I have to send a string - ie. http://server:1234/sendtext.cgi?num=234)

    Is there a way I can script my page to send a request to that page but have it hidden in the code?

    Let me know if that doesn't makes sense.. At present, I am using Response.Redirect to go to a page and then manually going back.

    Tuesday, August 12, 2014 1:15 AM

Answers

All replies

  • User-821857111 posted

    You can make the request from server-side code using the WebClient class.

    http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.110).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 12, 2014 1:41 AM
  • User-2051275383 posted

    Thanks for the prompt reply Mike,

    I found this article: http://stackoverflow.com/questions/5401501/how-to-post-data-to-specific-url-using-webclient-in-c-sharp

    Seems to have what I am after in it however I'd like to do it in Razor syntax - Are you able to point me in the right direction?

    Cheers!

    Tuesday, August 12, 2014 3:39 AM
  • User-821857111 posted

    The code that goes in a Razor block 

    @{
        ...
        here
        ...
    }

    is C#. You can use the code in that reply as-is.

    Tuesday, August 12, 2014 3:46 AM
  • User895691971 posted

    I think using POST request would be a better idea, it encrypts data a little bit and provides some layer for security.

    Also note that Razor in just the syntax. The language you use in ASP.NET is either C# or VB.NET. So if you found a tutorial for C#, then copy paste that code and make little alterations for variable names etc and you'll be good to go. As Mike has already said, all of the code inside the 

    @{
      // code
    }

    ..is C# so you won't have to worry. Don't get yourself confused by Razor and C#. C# is language, Razor is the syntax.

    Tuesday, August 12, 2014 4:14 AM
  • User-821857111 posted

    I think using POST request would be a better idea, it encrypts data a little bit and provides some layer for security.

    If the API requires query strings (GET), POST is no use. Also, POST adds no security at all. It doesn't encrypt data in any way.

    Tuesday, August 12, 2014 4:22 AM