0
我无法使用php post获取值。我的代码是:使用Java HttpURLConnection和php
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();
我节省$ _ SERVER,$ _GET,$ _ POST细节,但我不能让像GET,POST和服务器数据进行任何
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();
参数赋值。