i also try to send a http post.
I take the code from above
and change it for my case.
But unfortunately there is something wrong.
I want to send Date to my Yamaha AV Receiver RX-A1080.
There is a Web Interface and with this I record the HTTP POST Command
in Firefox Browser.
The Firefox Browser delivers also the data in a compact CURL command syntax so
you see better the data of the HTTP POST command in the following lines:
(as a CURL Command)
curl
'http://192.168.0.24/YamahaRemoteControl/ctrl'
-H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0'
-H 'Accept: */*'
-H 'Accept-Language: de,en-US;q=0.7,en;q=0.3'
--compressed
-H 'Referer: http://192.168.0.24/Setup/'
-H 'Content-Type: text/xml'
-H 'Connection: keep-alive'
--data '<?xml version="1.0" encoding="utf-8"?><YAMAHA_AV cmd="PUT"><System><Speaker_Preout><Pattern_1><PEQ><Manual_Data><Front_L><Band_7><Q>0.500</Q></Band_7></Front_L></Manual_Data></PEQ></Pattern_1></Speaker_Preout></System></YAMAHA_AV>'
i convert that with: https://curl.trillworks.com/#json
and get this:
{
"url":"http://192.168.0.24/YamahaRemoteControl/ctrl",
"raw_url":"http://192.168.0.24/YamahaRemoteControl/ctrl",
"method":"post",
"headers":
{
"User-Agent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0)
Gecko/20100101 Firefox/62.0",
"Accept":"*/*",
"Accept-Language":"de,en-US;q=0.7,en;q=0.3",
"Referer":"http://192.168.0.24/Setup/",
"Content-Type":"text/xml",
"Connection":"keep-alive"
},
"data":
{
"<?xml version":"\"1.0\" encoding=\"utf-8\"?><YAMAHA_AV cmd=\"PUT\">
<System><Speaker_Preout><Pattern_1><PEQ><Manual_Data><Front_L><Band_7><Q>0.500</Q></Band_7></Front_L></Manual_Data></PEQ></Pattern_1></Speaker_Preout></System></YAMAHA_AV>"
}
}
The Code i was written was that:
( i am not sure if there are to many slashes in JSONObject data ??? )
// Gesamt JSON Object
JSONObject post_dict = new JSONObject();
try {
post_dict.put("url", "http://192.168.0.24/YamahaRemoteControl/ctrl");
post_dict.put("raw_url", "http://192.168.0.24/YamahaRemoteControl/ctrl");
post_dict.put("method", "post");
// headers - JSON Object ////////////////////////////////////////////
JSONObject headers = new JSONObject();
headers.put("User-Agent","Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0");
headers.put("Accept","*/*");
headers.put("Accept-Language","de,en-US;q=0.7,en;q=0.3");
headers.put("Referer","http://192.168.0.24/Setup/");
headers.put("Content-Type","text/xml");
headers.put("Connection","keep-alive");
post_dict.put("headers", headers);
// data - JSON Object ////////////////////////////////////////////
JSONObject data = new JSONObject();
data.put("<?xml version","\\\"1.0\\\" encoding=\\\"utf-8\\\"?><YAMAHA_AV cmd=\\\"PUT\\\"><System><Speaker_Preout><Pattern_1><PEQ><Manual_Data><Front_L><Band_7><Gain><Val>-200</Val><Exp>1</Exp><Unit>dB</Unit></Gain></Band_7></Front_L></Manual_Data></PEQ></Pattern_1></Speaker_Preout></System></YAMAHA_AV>");
post_dict.put("data", data);
} catch (JSONException e) {
e.printStackTrace();
}
new YourAsyncTask().execute(String.valueOf(post_dict));
Could somebody say me whats wrong :-(
For more Information of the recorded command done by Firefox
you can see the following lines. (But they are similiar to the CURL Command)
New Request
============
POST http://192.168.0.24/YamahaRemoteControl/ctrl
Request-Header:
===============
Host: 192.168.0.24
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0
Accept: */*
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://192.168.0.24/Setup/
Content-Type: text/xml
Content-Length: 272
Connection: keep-alive
Request-Body:
=============
<?xml version="1.0" encoding="utf-8"?>
<YAMAHA_AV cmd="PUT">
<System>
<Speaker_Preout>
<Pattern_1>
<PEQ>
<Manual_Data>
<Front_L>
<Band_7>
<Gain>
<Val>-10</Val>
<Exp>1</Exp>
<Unit>dB</Unit>
</Gain>
or
<Freq>1.26 kHz</Freq>
or
<Q>0.500</Q>
</Band_7>
</Front_L>
</Manual_Data>
</PEQ>
</Pattern_1>
</Speaker_Preout>
</System>
</YAMAHA_AV>