My project requires contacting a PHP script hosted online. First the project should post a string to the PHP to be processed and returned from the PHP. So in my C#, I call UnityWebRequest.Post followed by UnityWebRequest.Get. Only the Post has issues. The Get request works perfectly as intended (the PHP returns a default set of data if the Post request doesn't do anything).
List<IMultipartFormSection> dataForm = new List<IMultipartFormSection>();
dataForm.Add(new MultipartFormDataSection("difficulty=Easy"));
UnityWebRequest www = UnityWebRequest.Post(webpage, dataForm);
yield return www.SendWebRequest();
This was the latest method I attempted using. Previously I used WWWForms and also tried to Post the string directly into the method. None of these worked. The Get request in Unity works fine, so I figured it might be the PHP that might be the problem.
$difficulty = $_POST["difficulty"];
if (!isset($difficulty)) {
$difficulty = "Hard";
}
But I wasn't convinced the PHP was broken since it works perfectly if $difficulty is set using the GET method through the URL (currently the project is using WebClient from System.Net and works perfectly which further convinces me that the PHP isn't the issue). So what's exactly the issue with UnityWebRequest.Post here?
You need to do a comma not equal operator.
dataForm.Add(new MultipartFormDataSection("difficulty", "Easy"));
Related
The Library Im Using: https://github.com/Code-Building/requests
PHP
if (register($_GET['username'], $_GET['password'], $_GET['hwid'])) { ... }
```
C++
http::request* result = http::post("https://xxx/api/handle.php?t=", data);
printf("%s", result->text.c_str());
I would like to add running this on a local server works just fine, having issues with livenet since thats what our teacher wants.
Also the issue is sending the post data. Manually entering post data / sending with fiddler work just fine. Any Ideas?
(Ive also used $_POST didnt work aswell)
I'm trying out Azure Functions using PHP.
Getting the request information is not working for me.
I've not been able to find any documentation at all with the information of how to use Azure Functions with PHP code.
According to the only couple of examples, it seems that in order to retrieve the input information you need to first get the content of the req variable (or whatever name you assign in the function configuration).
That has the path of the file containing the request information (in theory).
$input_path = getenv('req');
So far, if I check the content of it, I get something like this:
D:\local\Temp\Functions\Binding\e2b6e195-02f7-481b-a279-eef6f82bc7b4\req
If I check if the file exists it says true, but the file size is 0.
Do anyone knows what to do here? Anyone with an example? Does anyone know where the documentation is?
Thanks
Ok, unfortunately there's pretty limited documentation out there for php as you have discovered.
At present, looking at the code might be the best doc. Here is the InitializeHttpRequestEnvironmentVariables function that adds request metadata to the environment for the script languages (node, powershell, php, python).
Important environment variables are:
REQ_ORIGINAL_URL
REQ_METHOD
REQ_QUERY
REQ_QUERY_<queryname>
REQ_HEADERS_<headername>
REQ_PARAMS_<paramname>
I'm assuming you've made a GET request, in which case there is no content (req is an empty file), but you will see that these other environment variables contain request data. If you were to make a POST request with a body then req would have data.
here is a full example parsing a GET request in PHP with an Azure Function :)
https://www.lieben.nu/liebensraum/2017/08/parsing-a-get-request-in-php-with-an-azure-function/
snippet from source:
<?php
//retrieve original GET string
$getReqString = getenv('REQ_QUERY');
//remove the ? for the parse_str function
$getReqString = substr($getReqString,1,strlen($getReqString));
//convert the GET string to an array
$parsedRequest = array();
parse_str($getReqString,$parsedRequest);
//show contents of the new array
print_r($parsedRequest);
//show the value of a GET variable
echo $parsedRequest["code"];
?>
I have HHVM running on a virtualbox VM, with the webroot mapping to my local laravel install, being served out at an internal IP.
Locally, I'm serving the site out under http://[localhost]:8000.
The codebase is identical.
code of MembersController.php (resourceful controller):
public function show($id)
{
$member = Member::findOrFail($id);
$data = array();
$data['id'] = $member->id;
$data['first_name'] = $member->first_name;
$data['last_name'] = $member->last_name;
return Response::json($data);
}
Assuming everything is working normally:
When I run a GET request to LOCALHOST: http://[localhost]:8000/api/v1/member/1, the client returns the JSON as normal - all good.
When I run a GET request to HHVM (same client, identical codebase): http://[vm_ip_address]/api/v1/member/1, the client receives no data.
The data is being passed back through the calls within HHVM though, as if I change the 'return' to 'echo', the payload is returned in both cases (headers also)
It looks like HHVM is affecting with laravel's Response::json() function and disallowing the reply contents from being displayed in the client.
Has anyone else seen this?
This is not something I can set up a unit test for, as it always passes, because the final reply always has data in it :/
Any input would be great - I'm interested to learn how to get around this.
Thanks.
Sadly you're probably going to have to get your hands dirty debugging. HHVM probably has a very slight difference in how it does something which this code-path is sensitive to. We pass 100% of laravel unit tests, but there probably isn't one covering this case.
If you can, please trace down the code to where the data changes. Put in echos and error_logs until you can build a very small test case then then open an issue on github and we'll get it fixed.
I'm using the Zend Framework and jQuery.
I'm calling a JavaScript function, which sends POST-Data to a PHP scripts and waits for an answer.
Everything worked fine this morning. I'm using Debian.
The values are send via the header, Firebug gives me the following Output:
Parameterapplication/x-www-form-urlencoded
endDatum
funktionsId 1
mitgliederId 10368
startDatum 31.03.2013
Quelle
mitgliederId=10368&funktionsId=1&startDatum=31.03.2013&endDatum=
But neither the $_POST Variable or the Zend Framework Method $this->getRequest()->getParams(); gives me anything.
Any idea what's wrong?
Maybe something is wrong with my php.ini Settings?
What settings can I change to modify the header-output?
Solved it: the problem was the subdomain i set up for the page. The AJAX-Reuquest weren't called correctly
Try this for getting post values...
$this->getRequest()->getPost();
or for individual form elements
$this->getRequest()->getParams('elementName');
I have the following problem : On my local development server PHP 5.3.10 / Apache 2 every things goes right. When I run the same code with the production server PHP Version 5.2.13 / Apache 2 the code fail but on certain conditions not always.
More details :
The context : I have a dojox.data.grid table on the screen that can be updated. The modified data is correctly passed to the server as a JSON string. Like this :
data = {
"deletedItems":{}
,"newItems":{}
,"modifiedItems":{
"2890":{"idFacture":"2890"
,"idClient":"175"
,"idAffaire":"1323"
,"idContrat":"2234"
,"raisonSociale":"xxxxxx"
,"nomAffaire":"xxxxxx"
,"nrFacture":"xxxxx"
,"dateFacture":"2012-12-06"
,"montantFacture":"160000.00"
,"pourcentageFacture":"64.88"
,"pourcentageCalcule":"32.44"
,"noteFacture":""
,"dateTransfert":""
,"aTransferer":true
,"typeDocument":"Facture"
,"factureSoldee":false
,"montantTotalHeures":"0.00"
,"pourcentageTotalHeures":"0.00"
,"montantTotalMateriel":"0.00"
,"pourcentageTotalMateriel":"0.00"
,"montantTotalSousTraitance":"160000.00"
,"pourcentageTotalSousTraitance":"40.94"
}
,"2892":{"idFacture":"2892"
,"idClient":"50"
,"idAffaire":"1649"
,"idContrat":"2713"
,"raisonSociale":"xxxxx"
,"nomAffaire":"xxxxx"
,"nrFacture":"xxxxx"
,"dateFacture":"2012-12-07"
,"montantFacture":"12004.50"
,"pourcentageFacture":"0.00"
,"pourcentageCalcule":"41.94"
,"noteFacture":""
,"dateTransfert":""
,"aTransferer":true
,"typeDocument":"Facture"
,"factureSoldee":false
,"montantTotalHeures":"12004.50"
,"pourcentageTotalHeures":"41.95"
,"montantTotalMateriel":"0.00"
,"pourcentageTotalMateriel":"0.00"
,"montantTotalSousTraitance":"0.00"
,"pourcentageTotalSousTraitance":"0.00"
}
}
}
You can see that the data contains three elements "deletedItems" (empty), "createdItems" (empty) and "modifiedItems".
In the php code i have the following commands :
$srvJson = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$data = $srvJson->decode($data);
Where $data is filled like above. Normally after that last statement the folowing PHP variables are set :
$data["deletedItems"]
$data["createdItems"]
$data["modifiedItems"]
Here is the problem : if on the production server there are a lot of modified rows (about > 30) in the table, the modified data is correctly passed to the serveur BUT $data["modifiedItems"] is not set ??? If I just modify the dataset for a few rows $data["modifiedItems"] is well set.
I can modify the whole data set piece per piece, but not the whole dataset in one time.
I suppose this is a question of server settings but what ?
I would appreciate any suggestion.
Best regards,
Roger
PS : Sorry for my english
Since it is not valid JSON (checked with http://jsonlint.com/) the results of json_decode() in PHP 5.3.10 and PHP 5.2.13 are different!
While 5.3 returns nothing 5.2.13 returns the initial string. Probably your code has somewhere some error corrections...
See the different results of the different PHP version on 3v4l.org!
When us remove data = from your JSON does not throw errors..
Based on your above issue, you can check following things on server
magic_quotes are open or closed on server similiar to local server
Does Services_JSON is compitable to PHP 5.3
Services_JSON is pear php library so please check that it is working properly with all extension of php
http://pear.php.net/bugs/search.php?cmd=display&package_name%5B%5D=Services_JSON
Or you can use the default php json library for encode and decode
May this will help you