23

This question shows how to read a chunked response in Javascript, but I would like to send a chunked HTTP POST from Javascript. The documentation for XMLHttpRequest doesn't mention anything. Does the answer to this question mean that it's not possible due to browser restrictions on setting the header?

1
  • 3
    You could do this with simple polling on the client and making periodic POST(s). As long as your remote process does not serialize access then you should be fine. You could add a custom header to identify the sequence or task for server side correlations. Commented Dec 16, 2017 at 3:17

3 Answers 3

2

I don't think you can with XMLHttpRequest - it's old and somewhat limited, it's really just a backwards compatibility hack for a long-gone IE ActiveX component.

However, at the bleeding edge (not in Firefox yet) you can with fetch and TransformStream. This lets you send a stream from JS.

Sign up to request clarification or add additional context in comments.

Comments

1

Refer to this MDN page about Transfer-Encoding. You can set the type to chunked.

You have to specify how long each chunk will be, but it allows you to send data in chunks.

Comments

1

I think XMLHttpRequest is very old, I think the alternative is to use Axios which is a newer JavaScript package which helps to handle network requests. It is much more easier than fetch and ajax in JavaScript.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.