I need to hit a php script which takes some data from- _POST , _REQUEST and _FILES
I echoed the key value pairs that are coming in these - _POST and _REQUEST has some key and string value pairs, and _FILE had a key with an array of values as it's value- ie : key-'p_up_file' value-> Array -> [name] 'test', [type] plain/txt , ....
I need to hit this php file with Java POST http request. Not very familiar with php codes, so not sure how to set the java post entity such that the php script processes it properly in this case.
Even with POSTMAN, Iam not quite sure how the php expects the values to be sent such that these _POST, _REQUEST and _FILES gets populated with the required key values. IS there someway to differentiate them like that, such that it mimics the form upload?
Gave the variables expected in _POST key -> value pair like this -
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://localhost:8080/WebService/test.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("f_name", "Foo"));
nameValuePairs.add(new BasicNameValuePair("l_name", "Bar"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = null;
try {
response = client.execute(post);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
The PHP code is taking values like the following samples -
$_POST[P_TOKEN_KEY] , $_REQUEST['p_rootdir'] , $_REQUEST['p_username'],
$p_upload_file_name = $_FILES[p_up_file][name];
$p_upload_file = $_FILES[p_up_file][tmp_name];
Not sure how to send the array values along with this