Programming • Page 16

Discussion in 'Technology Forum' started by Dirty Sanchez, Mar 5, 2016.

  1. Jacob

    Untrusted Prestigious

  2. Jacob

    Untrusted Prestigious

    i fixed the 404 error but now it's timing out
     
  3. Jacob

    Untrusted Prestigious

    also we're basically firing all of our devs. so we're hiring.
     
  4. noxee

    Regular Supporter

    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.
     
    Jacob likes this.
  5. Jacob

    Untrusted Prestigious

    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
     
  6. Timmiluvs

    I play video games fast -- @Timmiluvs Prestigious

    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.
     
    Jacob likes this.
  7. Jacob

    Untrusted Prestigious

    I'll check. I'm away from my computer rn but will let u know if I make any progress
     
  8. Jacob

    Untrusted Prestigious

    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.
     
  9. Jacob

    Untrusted Prestigious

    
    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.
     
  10. Jacob

    Untrusted Prestigious

    why I did I never teach myself backend code :tear:
     
  11. noxee

    Regular Supporter

    What's the output of var_dump($_POST)?
     
  12. Jacob

    Untrusted Prestigious

    is that the response string? how do I get that info sent back as a response?
     
  13. Jacob

    Untrusted Prestigious

    oh wait
    i think i know what's going on
     
  14. Jacob

    Untrusted Prestigious

    welp i did mess something up but I fixed but no luck
     
  15. noxee

    Regular Supporter

    Are you seeing anything in the when you do var_dumps($_POST)?
     
  16. Jacob

    Untrusted Prestigious

    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?
     
  17. Jacob

    Untrusted Prestigious

    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);
    
    }
    
    
     
  18. Jacob

    Untrusted Prestigious

    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.
     
  19. noxee

    Regular Supporter

    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.
     
    Jacob likes this.
  20. Jacob

    Untrusted Prestigious

    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
     
  21. noxee

    Regular Supporter

    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.
     
    Jacob likes this.
  22. Jacob

    Untrusted Prestigious

    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.
     
  23. Jacob

    Untrusted Prestigious

    IMG_4544-1.PNG
    woohoo! thanks again @noxee, huge help.
     
    Timmiluvs likes this.
  24. Timmiluvs

    I play video games fast -- @Timmiluvs Prestigious

    Was just catching up here when I saw that.

    Working for you now?
     
    Jacob likes this.
  25. Jacob

    Untrusted Prestigious

    Yup! gonna testing with my coworker but as far is I can tell if it's working for me it'll work for everyone.
     
    Timmiluvs likes this.