verstappen_doodle
verstappen_doodle

Reputation: 549

How to send un-named XML data in POST body using HTML form?

This is my current request model (using AJAX XMLHTTP):

POST someURL/someURL/someURL HTTP/1.1
Host: xxx.yyy.com
Connection: close
Content-Length: 221
Origin: https://xxx.yyy.com
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
Content-type: text/xml;charset=UTF-8
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8


<zadata>SOMEXMLDATA</zadata>
 

I'm just sending a un-named XML data in the body of AJAX XMLHTTP request.

I want to achieve the same without AJAX (using HTML FORM or some other method), as I'm requesting this resource from another domain, and I need to render the response directly in the webpage. (AJAX won't work due to SOP)

I tried many enctype in <form>, but couldn't achieve it. Help?

Update: I tried inserting one part of XML inside <input> name attribute, and another part inside <input> value attribute. Like this:

XML data: <zadata><param data=someValue></param></zadata>

<input type="text" name ="<zadata><param data" value="someValue></param></zadata>">

The request goes like this: %3Czadata%3E%3Cparam+data=someValue%3E%3C%2Fparam%3E%3C%2Fzadata%3E

The = symbol was inserted and the format is fine in request, but browser URL-encodes the content. Any way to prevent this encoding?

Upvotes: 1

Views: 1256

Answers (2)

verstappen_doodle
verstappen_doodle

Reputation: 549

enctype attribute with value text/plain in <form> worked well. This is how I achieved it:

<form action="http://someURL.com" method="POST" enctype="text/plain">
<input type="text" name ="<zadata><param data" value="someValue></param></zadata>">
<input type="submit" value="Submit request">
</form>

The request model now:

POST http://someurl.com/ HTTP/1.1
Host: someurl.com
Content-Length: 47
Cache-Control: max-age=0
Origin: null
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
Content-Type: text/plain
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
Connection: close

<zadata><param data=someValue></param></zadata>

Upvotes: 0

Quentin
Quentin

Reputation: 944010

This is impossible. That isn't a format supported by forms.

but browser URL-encodes the content. Any way to prevent this encoding?

… yes. Make it a multipart request instead. It will then be multipart encoded instead, which still isn't what you want.

You can't get the format you are asking for using a plain HTML form.

Upvotes: 1

Related Questions