C# Encoding a text string with line breaks

Yes – it means you’re using \n as the line break instead of \r\n. Notepad only understands the latter. (Note that Environment.NewLine suggested by others is fine if you want the platform default – but if you’re serving from Mono and definitely want \r\n, you should specify it explicitly.)

Return generated pdf using spring MVC

You were on the right track with response.getOutputStream(), but you’re not using its output anywhere in your code. Essentially what you need to do is to stream the PDF file’s bytes directly to the output stream and flush the response. In Spring you can do it like this: @RequestMapping(value=”/getpdf”, method=RequestMethod.POST) public ResponseEntity<byte[]> getPDF(@RequestBody String json) … Read more

Download File from Bytes in JavaScript

I asked the question long time ago, so I might be wrong in some details. It turns out that Blob needs array buffers. That’s why base64 bytes need to be converted to array buffers first. Here is the function to do that: function base64ToArrayBuffer(base64) { var binaryString = window.atob(base64); var binaryLen = binaryString.length; var bytes … Read more

Express.js Response Timeout

There is already a Connect Middleware for Timeout support: var timeout = express.timeout // express v3 and below var timeout = require(‘connect-timeout’); //express v4 app.use(timeout(120000)); app.use(haltOnTimedout); function haltOnTimedout(req, res, next){ if (!req.timedout) next(); } If you plan on using the Timeout middleware as a top-level middleware like above, the haltOnTimedOut middleware needs to be the … Read more

if-modified-since vs if-none-match

Regarding the differences between Last-Modified/If-Modified-Since and ETag/If-None-Match: Both can be used interchangeably. However depending on the type of resource, and how it is generated on the server, one or the other question (“has this been modified since …?”https://stackoverflow.com/”does this still match this ETag?”) may be easier to answer. Examples: If you’re serving files, using the … Read more

What are Content-Language and Accept-Language?

Content-Language, an entity header, is used to describe the language(s) intended for the audience, so that it allows a user to differentiate according to the users’ own preferred language. Entity headers are used in both, HTTP requests and responses.1 Accept-Language, a request HTTP header, advertises which languages the client is able to understand, and which … Read more

java.lang.IllegalStateException: Cannot (forward | sendRedirect | create session) after response has been committed

A common misunderstanding among starters is that they think that the call of a forward(), sendRedirect(), or sendError() would magically exit and “jump” out of the method block, hereby ignoring the remnant of the code. For example: protected void doXxx() { if (someCondition) { sendRedirect(); } forward(); // This is STILL invoked when someCondition is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)