So looking at the URL path I'm not sure you're accessing the right location. /var/www/html/owt is a server path and isn't usually what will appear in the browser URL. Your Apache config probably looks something like this <VirtualHost *:80> DocumentRoot /var/www/html/owt/ ServerName 45.33.35.13 . . . </VirtualHost> That means if on the server your file is located in /var/www/html/owt/test.php then you would access it at http://45.33.35.13/test.php But without seeing your full Apache config it's hard to say. If you want me to have a look at it you can PM me.
darn I thought this was it. I did change the document root to that, changed my url to http://45.33.35.13/test.php and it still doesn't work
This error makes me think your POST request is malformed in some way. It could be that your front end is encoding something in JSON while the backend is expecting it encoded in XML for example. I'd double check to make sure that everything being sent in the POST matches up to and is formatted to be what the backend is expecting.
so question, I have the PHP script, it works, notifications are working and the only thing i need to do is have that PHP script get the POST variables and insert those into the notification instead of the default "Hello from PHP". Any advice on how to do that? been researching on my own but getting conflicting info.
UALog::setLogHandlers(array(new StreamHandler("php://stdout", Logger::DEBUG))); $airship = new Airship("hidden", "hidden"); echo $_POST['token']; echo $_POST['msg']; $token=$_POST['token']; $message = array('aps'=>array('alert'=>$_POST['msg'])); try { $response = $airship->push() ->setAudience($token) ->setNotification(P\notification($_POST['msg'])) ->setDeviceTypes(P\all) ->send(); } catch (AirshipException $e) { print_r($e); } what i've been trying.
i added that to the file and got the same response, not really sure how to view the contents of var_dumps. it has to be in the response string right?
well I changed everything back and it works again. only thing I need to do is send the POST request and then in PHP $token = $_POST["token"] $msg = $_POST["msg"] try { $response = $airship->push() ->setAudience(P\deviceToken($token)) ->setNotification(P\notification($msg)) ->setDeviceTypes(P\all) ->send(); } catch (AirshipException $e) { print_r($e); }
but when i tried that I get a 500 error response. doesn't make sense. I'm very inexperienced with PHP. as in this is the first time iv'e used it haha so idk really know how to debug with it.
So instead of var_dumps if you use print_r($_POST) you should be able to see every variable available in the $_POST object. I would check that both token, and msg are valid keys in the $_POST object.
i'm fairly certain my JSON object is correctly made. Made the dictionary, did json = try? JSONSerialization.data(withJSONObject: msg, options: .prettyPrinted) request.addValue("application/json", forHTTPHeaderField: "Content-Type") request.httpBody = json
If you're trying to process JSON data in PHP you need to do something like $content = file_get_contents("php://input"); $decoded = json_decode($content, true); echo($decoded['msg']); echo("\n"); echo($decoded['token']); Have a look at this post for more info on capturing JSON data Receiving JSON POST data via PHP.
ya i just realized that too haha. "responseString = Optional("Hoot! Another event has hatched near you!\n2186c9347e4aaf2a72b482fcdefe6f05a6933c08cfb90f4103865031087d190f")" will have to force unwrap to get rid of that optional. that all works but as soon as a touch the $response = $airship->push() ->setAudience(P\all) ->setNotification(P\notification("legalize ranch")) ->setDeviceTypes(P\all) ->send(); part of code it gives me the 500 error. So I think I think that's an API thing.
Yup! gonna testing with my coworker but as far is I can tell if it's working for me it'll work for everyone.