Ok, first thing: I am not responsible for this code. I am dealing with a router. This router has a web interface, and the code I'm about to show is in the router's web interface. My job is to build an app to configure this router. And I need my app to perform the login operation in the router.
The thing is: the developers that created the web interface for this router, made the router accept a post request in which the body of the request is xml, and the content type is application/x-www-form-urlencoded
!!!! (whaaaaaat???)
The source code that generates this request is in the page:
function PostXML_log(pUrl, value) {
$.ajax({
type: "POST",
dataType: 'xml',
url: pUrl,
processData: false,
data: value,
async: true,
beforeSend: function () { show_message("wait"); },
success: function (data) {
var code = $(data).find('CODE').text();
if (code == "0" || code == "-1") {
$.cookie.json = false;
$.cookie("stork", $(data).find('MESSAGE').text(), { expires: 1 });
if (code == "-1")
window.location = "mac_err.html";
else
location.href = "../main_status.html";
}
else show_message("error", err_message)
},
error: function () { show_message("error", 'loading Error...'); },
timeout: 20000
});
}
function loginIn() {
var username = 'admin';//$('#username').val();
var password = ASCII2HEX($('#login_pwd').val());
var xml = '<?xml version="1.0" encoding="utf-8"?><LOGIN><USER_NAME>' + username + '</USER_NAME><PASSWD>' + password + '</PASSWD></LOGIN>';
PostXML_log("/cgi-bin/cgi.cgi?/app/route/login", xml);
};
The problem is that I can't find a way to replicate this behavior using Postman. I couldn't find a way to send a body and use application/x-www-form-urlencoded
as content type at the same time.
I tried 4 different strategies with no success:
1 - Send as body, using content type application/xml, results in no response being received (send as pure text or text/xml results the same):
2 - Send xml as form key, results in error
3 - Send xml as form value, results in error
4 - send xml as both key and value, error: (i tried putting the xml's <xml>
tag as key and the <login>
tag as value, as well as putting the whole xml as key and value, no luck)