#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    28
    Rep Power
    0

    How to use snoopy class


    Hi,



    I am using snoopy class to pass the json encoded to site. However if i pass the values using url as:



    $values= array(
    'val' => 'val1',
    'val_arr' => "val1", "val2")
    );







    $url = 'path to webservice?values='.json_encode($values);



    it gives me correct output by using $_GET as in format



    {"val":"val1", "val_arr":["val1", "val2"]}



    however by using post method of snoopy class





    $snoopy = new Snoopy();

    $snoopy->submit($url,json_encode($data);



    on receivng end of webservice it gives output as:



    Array[0]=>({"val":"val1", "val_arr":["val1", "val2"]})



    How can i post the data in json encoded string format using snoopy??
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,914
    Rep Power
    1045
    Hi,

    please, use code tags. I don't wanna have to search the PHP snippets in your text.

    Your POST request makes no sense to me. The data passed to submit is supposed to be an array. You pass a string instead, namely json_encode($data). How is that supposed to work?
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers? There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    please, use code tags. I don't wanna have to search the PHP snippets in your text.

    Your POST request makes no sense to me. The data passed to submit is supposed to be an array. You pass a string instead, namely json_encode($data). How is that supposed to work?
    I am sendind data to webservice and webservice is receiving the data via POST. So i have to use send data via post using:

    $snoopy->submit($url, json_encode($data))
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by new_member
    I am sendind data to webservice and webservice is receiving the data via POST. So i have to use send data via post using:

    $snoopy->submit($url, json_encode($data))
    getting the values via post does not give required string format rather it gives the output as i posted in first comment
  8. #5
  9. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,914
    Rep Power
    1045
    Yes, I understand that. But appearently you didn't understand that I'm trying to tell you: The submit() expects you to pass an array for the data. But you pass a string instead.

    Compare this:

    PHP Code:
    $snoopy->submit($url, array('x' => 10)); 
    to your code:

    PHP Code:
    $snoopy->submit($urljson_encode($data)) 
    See the difference? json_encode($data) is a string. But you need an array.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers? There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by Jacques1
    Yes, I understand that. But appearently you didn't understand that I'm trying to tell you: The submit() expects you to pass an array for the data. But you pass a string instead.

    Compare this:

    PHP Code:
    $snoopy->submit($url, array('x' => 10)); 
    to your code:

    PHP Code:
    $snoopy->submit($urljson_encode($data)) 
    See the difference? json_encode($data) is a string. But you need an array.
    thats the problem i need to pass the data in json encoded string to api
  12. #7
  13. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    501
    Rep Power
    127
    PHP Code:
    $snoopy->submit($url,array("values"=>json_encode($data)); 
    Snoopy won't know what to name your string in the POST if you don't pass it as an associative array. Based on your GET string you want it called "values", so it'd be like the above.
    LinkedIn: Dave Mittner
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by dmittner
    PHP Code:
    $snoopy->submit($url,array("values"=>json_encode($data)); 
    Snoopy won't know what to name your string in the POST if you don't pass it as an associative array. Based on your GET string you want it called "values", so it'd be like the above.
    That worked. Thanks

IMN logo majestic logo threadwatch logo seochat tools logo