I am creating a string variable in javascript and the length of that string could be any.
I am sending this string by jquery post method to a servlet. This servlet writes the string to a file.
I can alert the string anywhere in my javascript and can see the complete string.
But whenever the string length exceeds 5345 characters, then I get "aborted" message in firebug (I assume data is not sent) and no error message is displayed in server's console.
(For chrome, length limit is little more i.e. 5389)
I guess there is a problem in length of the data that is being sent to the servlet. But I wonder, to my knowledge there is no limit to the amount of data sent by post.
I am using jquery's $.post method as below
$.post('servlet', function(data) {
});
I want to print the error that has occurred while sending data to the servlet. Can I do that?
If you are using the GET method, you are limited to a maximum of 2,048 characters, minus the number of characters in the actual path.
However, the POST method is not limited by the size of the URL for submitting name/value pairs. These pairs are transferred in the request body and not in the URL.
Related
I am receiving an ID that is encrypted from the backend and I can see in the response it is coming without any question marks. But when passing this value in a request, I see some values are being changed. We are simply taking this value and passing it. Why would this be?
Example:
Getting from backend... ID = 7$ĄrÂŬÛ,ŕ4Ŀ+
While passing to another service... ID = 7$?rÂ?Û,?4?+
Edit: a few things to note
this is all happening within an iFrame
on page load, initial value is held in redux as an empty string ('')
issue does not happen when characters from the extended ascii table are not there, but only some ascii characters are changing to ?
Well, without any code to see what's really happening, I have a few guesses on what could be going on.
If the text is still encrypted or it's partially encrypted, then there won't actually be any character to display because it's in an encrypted binary format.
Make sure the encrypted text is being fully decrypted.
Character Support
If you are viewing the encrypted text in a terminal, it may not be able to display the characters correctly, (as those specific characters are only supported in
Unicode,
and not in
ASCII).
Try outputting the text to a file.
If you are sending the request in a URL, the URL can only take certain characters without special formatting, only a subset (64) of the characters from the ASCII character set can be used.
Make sure it's being encoded (and decoded) with
base64
for
URLs
and
forms.
I have been breaking my head for the last couple of days trying to save the screenshot from a ThreeJS on the server using .NET Web API.
I have gone through all the possible questions on this specific topic and related ones on StackOverflow and tried the suggestions as well.
The issue details are specified below:
I am successfully able to get the base64 encoded string from renderer.domElement.toDataUrl() which contains a valid threejs image.
When I pass this string as is to my .NET WebAPI, the Convert.FromBase64String() method fails saying invalid length of the Base64 string or invalid padding characters. I ensured to extract out the "data:image/png;base64," part before passing.
I tried a number of things to resolve this issue like adding padding characters to ensure the length is mod 4, using regular expression to extract out the right data. I was able to get through the Convert.FromBase64String() and saved the resulting byte array as a png on my server. It resulted in a blank image.
I also discovered that when I used the chrome extension Advanced Rest Client to hit my WebAPI and used the Encode Payload feature before posting the string, I was able to get the image saved on my server successfully and got back the desired image as well.
Seeing this, I used the encodeURIComponent() function in Javascript to pass my base64 string to the WebAPI from my web app, but failed, getting back the same behavior as my earlier attempts.
One important observation was that the whitespaces were getting eliminated in case of Encode Payload but not in case of encodeURIComponent.
I compared the strings between encodeURIComponent() and the Encode Payload from Advanced Rest Client. Although, on a high level, they do the same thing by replacing the special characters with their escape sequences, there is still a significant difference between them.
Request help on this issue.
I would like to know if there is any other way of getting the threejs base64 string passed to .NET successfully.
What might be the difference between the encoding of encodeURIComponent and Advanced Rest Client Encode Payload feature?
Thanks in advance!
I am submitting data to the server using UTF-8 and encoding all entries being sent to the server. The objects I am sending are parameters with accompanying JSON data that partly consists of special characters.
For example, for the description field of the JSON data, the actual input into a textarea is:
!##$%^&*()
""''
this is a new line
The UTF-8 encoded data being sent to the server looks like:
&line={"description":"!%40%23%24%25%5E%26*()%0A%22%22''%0A%0Athis%20is%20a%20new%20line"}
with the parameter being 'line'.
On the server side, I am trying to parse the line parameter, but it has been decoded back into a readable string, with the special characters and new lines looking exactly like they did in the input data, albeit as part of JSON. When I try to parse this string into JSON, which now looks like:
{"description":"!##$%^&*()
""''
this is a new line"}
I get the 'SyntaxError: Unexpected token' error, which is expected assuming that it is caused by the breaks in the string. How would I rectify this issue? I have tried re-encoding the string using encodeURIComponent, but that encodes literally every element of the string.
I will ultimately be saving this data as part of a document in a NoSQL solution; the parsing is being done as part of a validation procedure to ensure entry data is of proper JSON format.
I would like to determine te size (in bytes?) of a HTTP POST transaction to be submitted. I have a form with a lot of form data. When all fields are filled with the maximum number of characters (for example all 9's) and the form gets submitted through a POST method, there's no problem, and all data gets saved.
When I replace all characters (9's) by spaces, I get a 404 after submitting the form.
I'm assuming that I'm sending too much data here. I think the spaces are being converted to %20, so the amount of bytes posted are tripled.
I would like to determine the size of the HTTP POST transaction, before submitting the form, so I can display a message to the user if the size is over some limit. I'd prefer to use JavaScript.
Does anyone know how to determine this?
A 404 error indicates that the location you are trying to post to does not exist, i.e. the URL may be malformed when you post with spaces.
Can you show us the code?
There's no limit for POST data (except if it's a WCF service or something) - I would look if you are correctly posting the FORM data since 404 is a PAGE NOT FOUND error and has nothing to do with the format...
Any more code to show maybe?
I'm using JQuery '.serialize' + '.post' to send form data using ajax to a non-unicode, asp based website. The result data is url-encoded in unicode (characters are encoded in double values).
Can I post the form data encoded like it's sent using the form submit(), using JQuery ajax?
Ok, after hours and hours of trying...
Javascript uses UTF-8 for strings, and AJAX requests are always sent with UTF-8, period. There will always be a conversion on the server side if UTF-8 is not supported.
Description in the JQuery contentType parameter states:
Data will always be transmitted to the server using UTF-8 charset; you
must decode this appropriately on the server side.
So, eventhough there are QA's which claim some solutions as working, they are simply some conversions on the client & the server side. So firefox's firebug will always show UTF-8 characters on the net panel for AJAX requests, and it will never look like a submitted form with single byte characters.
You can use
var encStr = encodeURIComponent(str)