0

I can't get the value using php post. My code is:

InputStream is;
URL url = new URL(targetURL);
String request = "request=" + parameter;
Log.d("Light", "Url data:" + request);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(request);
wr.flush();
wr.close();

parameter value assign using

 JSONObject obj = new JSONObject();
 obj.put("id", requestModel.Id);
 obj.put("name", !requestModel.Name.equals("") ? requestModel.Name : MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
 obj.put(ManufacturesTableAdapter.KEY_MANUFACTURES_ADDRESS, !requestModel.Address.equals("") ? requestModel.Address : MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
 obj.put("city", !requestModel.City.equals("") ? requestModel.City : MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
 obj.put("state", !requestModel.State.equals("") ? requestModel.State : MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
 obj.put("zip", !requestModel.Zip.equals("") ? requestModel.Zip : MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
 obj.put(ManufacturesTableAdapter.KEY_MANUFACTURES_PHONE, !requestModel.Phone.equals("") ? requestModel.Phone : MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
 obj.put(ManufacturesTableAdapter.KEY_MANUFACTURES_EMAIL, !requestModel.Email.equals("") ? requestModel.Email : MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
 switch (apiName) {
     case JsonWriteContext.STATUS_OK_AFTER_COLON /*2*/:
         obj.put("questions", !requestModel.Questions.equals("") ? requestModel.Questions : MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
         break;
 }
 return obj.toString();

I save the $_SERVER, $_GET, $_POST details but I can't get anything like get, post and server data.

Cristik
  • 30,989
  • 25
  • 91
  • 127

1 Answers1

1

PHP fills the $_POST array when request uses certain Content-Type header (such as application/x-www-form-urlencoded or multipart/form-data) and request body is URLencoded query string (examples).

Also you can read raw data from the request body from php://input stream.

Community
  • 1
  • 1
Timurib
  • 2,735
  • 16
  • 29