I want to register a device with my Wordpress plugin. For this the Plguin uses the following code.
Sample request for new registration:
POST /pnfw/register/ HTTP/1.1
Host: yoursite
Content-Length: 26
Content-Type: application/x-www-form-urlencoded
token=new_device_id&os=iOS
Returns:
200 OK: on success.
401 Unauthorized: if OAuth is enabled but the signature is invalid (see below).
404 Not Found: if prevToken is not found on updating registration.
500 Internal Server Error: on missing mandatory parameters, unknown operating system, or general failure.
On errors:
On errors, besides the HTTP status codes defined above, a JSON is returned with this format:
This is the class the device registers with Firebase.
public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService {
private static final String REG_TOKEN = "REG_TOKEN";
@Override
public void onTokenRefresh() {
String recent_token = FirebaseInstanceId.getInstance().getToken();
Log.d(REG_TOKEN,recent_token);
sendRegistrationToServer(recent_token);
}
public void sendRegistrationToServer(String recent_token) {
}
}
I can not get the data from "recent_token" to my server. I tried the whole day.
public void sendRegistrationToServer(String recent_token) throws IOException {
String result = null;
HttpURLConnection urlConnection = null;
try {
String postData = "token=" + recent_token + "&os=Android";
byte[] postDataBytes = postData.getBytes("UTF-8");
URL url = new URL("http://www.bluestarfish.de/pnfw/register/");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setConnectTimeout(30000);
urlConnection.setReadTimeout(30000);
urlConnection.setRequestMethod("POST");
urlConnection.setDoOutput(true);
urlConnection.setRequestProperty("POST", "/pnfw/register/ HTTP/1.1");
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConnection.setRequestProperty("charset", "UTF-8");
urlConnection.setRequestProperty("Host", "www.bluestarfish.de");
urlConnection.setRequestProperty("Content-Length", Integer.toString(postDataBytes.length));
OutputStream out = urlConnection.getOutputStream();
out.write(postDataBytes);
out.close();
//result = readStream(urlConnection.getInputStream());
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
}
//return result;
}
Where is the failure Unfortunately, nothing happens. Can someone explain the mistake to me?