0
firebaseのクラウド関数を個別に呼び出そうとしましたが、jsonのパラメータにアクセスできないという点を除いてすべてがうまくいくようです。request.body.PARAMETER_NAME
は常に未定義を返しています。アンドロイドからFirebaseクラウドへのPOSTリクエストPOSTリクエスト
これは私のアンドロイドコードです:
try {
JSONObject jsonParam = new JSONObject();
jsonParam.put("param1", "v1");
jsonParam.put("param2", 2302355);
jsonParam.put("param3", "v2");
URL url = new URL(urls[0]);
HttpURLConnection connection;
connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Authorization", idToken);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setUseCaches(false);
connection.setAllowUserInteraction(false);
connection.setConnectTimeout(10000);
connection.setReadTimeout(10000);
//Write
OutputStream outputStream = connection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
writer.write(jsonParam.toString());
writer.close();
outputStream.close();
///
connection.connect();
int res = connection.getResponseCode();
a = (res == HttpURLConnection.HTTP_OK);
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
server_response = readStream(connection.getInputStream());
}
} catch (IOException e) {
e.printStackTrace();
}
//return (a) ? server_response : "Nothing";
return server_response;
私のサーバーコード:
exports.SOME_FUNCTION_NAME = functions.https.onRequest(function (request, response) {
if (!request.headers.authorization) {
console.error('No Firebase ID token was passed');
response.status(403).send('Unauthorized');
return;
}
admin.auth().verifyIdToken(request.headers.authorization).then(function (decodedIdToken) {
request.user = decodedIdToken;
response.send(request.body + '\n'+request.params+'\n'+request.data+'\n'+request.headers);
}).catch(function (error) {
console.error('Error while verifying Firebase ID token:', error);
response.status(403).send('Unauthorized ' + error);
});
});
これは私が取得しておく応答である:request.body.toJSON
については
[object Object][object Object][undefined][object Object]
を、私は間違っている可能性がどのような応答
としてundefined
を取得しますか?
ありがとうございます。