0

I'm currently working on a system that needs to be able redirect a consumer to a c# application using a form which POSTs data as a serialized JSON string along with the consumer.

So, the form would look something like this, essentially: -

<form action="c#methodLocation" method="post">
   <input type="text" value="<?php echo $safeFormatJson; ?>">
   <input type="submit" value="submit">
</form>

I would imagine an enctype would be needed, however I've tried "application/json" but the data is interpreted as UrlEncoded. Would text/plain work, or is it even possible to send strictly a serialized string as a POST?

I've tried using Jquery and AJAX to send the data a different way, but that method creates issues with the data being rewritten when the consumer arrives to the c# side, as a new session is inadvertently created when doing so.

Zerkeras
  • 327
  • 1
  • 2
  • 13
  • 1
    *.cshtml files are almost always used in an MVC application. In which case, that page is a view, and you can't POST data to it directly, JSON or otherwise – Jedediah Sep 16 '14 at 17:54
  • Not correct - in MVC you can use raw JSONP http://stackoverflow.com/questions/17822278/asp-net-mvc-read-raw-json-post-data – comdiv Sep 16 '14 at 17:57
  • Yes, but what @Jedediah is saying is that the `action` on the `
    ` is incorrect.
    – qJake Sep 16 '14 at 17:58
  • Yes, I see now... cshtml cannot be called directly – comdiv Sep 16 '14 at 18:06
  • the .cshtml action was mainly an example. I should have been more clear that it's posting to a Method, rather than a cshtml file. – Zerkeras Sep 16 '14 at 18:36
  • @Zerkeras You can always edit your question to be more clear. – Brian Rogers Sep 16 '14 at 18:44

1 Answers1

0

The only solution known by me is to catch onsubmit event and then send any hand-made-request you like

Here is pseudode with something jQuery-like (it can be prototype.js, angular.js or pure JS8)

(
 var form = $("#myform"); //find needed element in DOM
 var mySecretEncription = function(){.../*hard to understand secret*/}; //define your specials
 var myPost = function(){ //provide functionality to send valid request
     var myData = {};
     myData.superField  = mySecretEncription(form.select("input.myfield").value);
     $.http({
        url : "special-post-url or form.action attribute",
        method:"POST",
        headers:{... my special header ...},
        data :myData
     })
 }
 form.on("submit", mypost); //event subscription

)()

It's not code to copy, it's recepie

comdiv
  • 865
  • 7
  • 26