1
以下は私のホームオートメーションシステムで照明をオンに切り替えるための現在作業中のコードです。私は新しいシステムにアップグレードしており、変更されたポストコマンドが必要です。現在、私はこれがキーのペア "lightswitch1 = ON"を送信すると思います。私はそれを "ON"だけ送る必要がありますが、私はこれを行う方法がわかりません。以下は動作するCURLコマンドです。鍵以外のペアを持つAndroid投稿のリクエスト
public void turnonlight() {
String url = "http://example.com:8090/CMD";
StringRequest MyStringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//Toast.makeText(MjpegActivity.this,response,Toast.LENGTH_LONG).show();
//This code is executed if the server responds, whether or not the response contains data.
//The String 'response' contains the server's response.
}
},
new Response.ErrorListener() { //Create an error listener to handle errors appropriately.
@Override
public void onErrorResponse(VolleyError error) {
//Toast.makeText(MjpegActivity.this,error.toString(),Toast.LENGTH_LONG).show();
//This code is executed if there is an error.
}
}){
@Override
protected Map<String, String> getParams() {
Map<String, String> MyData = new HashMap<String, String>();
MyData.put(lightswitch1 "ON"); //Add the data you'd like to send to the server.
return MyData;
}
};
RequestQueue MyRequestQueue = Volley.newRequestQueue(this);
MyRequestQueue.add(MyStringRequest);
}
カール-X POST --header "のContent-Type:text/plainの" "同意する:アプリケーション/ JSON" --header -d "ON" "http://example.com:8090/CMD"
コードを送信しようとすると、「BasicNetwork.performRequest:予期しない応答コード400」というエラーが表示されます。私はワイヤーサメを使用し、作業要求と非稼働要求を嗅ぎました。右側のものは有効で、左側のものは無効です。右のように左のものを作るために私は何を変えることができますか? –
http://imgur.com/a/e6qvy –
コンテンツタイプが間違っていると思います。 –