AJAX problem (ing) JSON object on Mac Firefox version (3.6.12)

Let's say I want to call some server-side method and pass the following JSON object to it:

var t = { "test": 0}; 

I am using jQuery library $ .ajax method with the following parameters:

 type: "POST", async: true, url: 'mypage.aspx?Action=myAction, data: { test: JSON.stringify(t, null, 2) }, contentType: 'application/x-www-form-urlencoded', dataType: 'json', . . . 

On the server side, I retrieve the data using the following code:

  public string GetInputStream() { string inputContent; using (var sr = new System.IO.StreamReader(Request.InputStream)) inputContent = sr.ReadToEnd(); return Server.UrlDecode(inputContent.Split('=')[1]); } 

When called from browsers other than Mac Firefox version 3.6.12, the getinputstream method returns:

 test=%7B%0A++%22test%22%3A+0%0A%7D 

which is valid and then can be deserialized into an object, but when calling this method from Mac OS X 10.5.8 Firefox 3.6.12 I got a line that cannot be deserialized:

 test=%7B%0A++%22test%22%3A0%0A%Pr 

I believe that Pr at the end of the line confuses me and does not turn into a closing bracket. Any ideas?

EDIT: I looked at the Firebug Net> Call> POST tab and was surprised to see that the POST line is correct: test=%7B%0A++%22test%22%3A%220%22%0A%7D where else this POST line can be changed to get to the server with an invalid string?

EDIT2: An interesting search, all problems are resolved if HTTPS (secure) is used :-). I suppose this should be a security setting on Mac Firefox?

+4
source share
2 answers

I ended up modifying the GetInputStream () method to replace "% Pr" with a closing bracket using regex:

  public string GetInputStream() { string inputContent; using (var sr = new System.IO.StreamReader(Request.InputStream)) inputContent = sr.ReadToEnd(); inputContent = System.Text.RegularExpressions.Regex.Replace(inputContent, "%Pr$", "}"); return Server.UrlDecode(inputContent.Split('=')[1]); } 

I know this is not a solution to the problem, but at least I buy some time to come up with a solution :-(

0
source

I think this is a duplicate of jQuery AJAX Error in Firefox on Mac with "Managed" Users

The problem is the conflict between Firefox and parental controls on Mac OS X 10.5. The last two characters of the POST data are replaced by Pr. The problem was first reported two years ago, and it seems that it will not be fixed.

The best job that I know of is to use SSL, because it prevents the problem. If this is not an option, you need to add at least two characters to the end of your POST data, which can be ignored. In a form that would mean adding something like <input type="hidden" name "useless" value="useless"> to the end of the form (credit to Miquel Botanch ). For JSON / XML queries, the last few characters are important for parsing. If you can't just add spaces or newlines (maybe it would work, I would not try), then you need to add the other side of the dummy value of the client. Finally, on the server side, you will need to detect and remove this additional dummy value (as krul's answer).

0
source

Source: https://habr.com/ru/post/1338497/


All Articles