How to create a JSON POST request from a GET method

Let’s say you find a security hole in your system from old developers – leaving one of your webservices exposed:

http://mywebservice/MyService.asmx/SendEmail?Username=1234&Password=1224!&EmailFrom=no-reply@carra-lucia-ltd.co.uk&EmailTo=carra_lucia@hotmail.com&Subject=MySubject&Message=Dear%20Administrator,test%20mail%20here

Now how would you transform this into a POST string with JSON?


  var myURL = "http://mywebservice/MyService.asmx/SendEmail";
        var dataToUse = $.parseJSON('{"Username": "1234","Password":"1224!","EmailFrom":"no-reply@carra-lucia-ltd.co.uk","EmailTo":"carra_lucia@hotmail.com","Subject":"MySubject","Message":"' + msg + '"}');
        $.ajax({
            type: "POST",
            url: myURL,
            contentType: "application/json; charset=utf-8",
            dataType: "jsonp",
            data: dataToUse,
            crossDomain: true,
            success: function (response) {
                //email was sent
                alert("Email has been sent successfully!");
            },
            error: function (jqXHR, error, errorThrown) {
                if (jqXHR.status && jqXHR.status == 400) {
                    alert(jqXHR.responseText);
                } else {
                    alert("Something went wrong. We could not send your email.");
                }
            }
        });

MySubject

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s