Recieve variables in java Web Service from php cURL using POST?
I'm recieving 'null' on my Params. So far i've found people using
"PathParams", "FormParams" and "QueryParams" on java to get their
variables from the request, however in my case, using post i dont have
PathParams, and for some reason FormParams and QueryParams are returning
null as if i had never sent them. So i'd like help to solve this.
My php cURL POST request:
<?php
$url = "http://localhost:8080/TestRest/streams/add";
$params = "param1=val1¶m2=val2";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
My java Web Service:
@Path("/streams")
public class Streams {
@POST
@Path("/post")
@Produces(MediaType.TEXT_PLAIN)
@Consumes({"application/x-www-form-urlencoded"})
public String addStream(@QueryParam("param1") String param1,
@FormParam("param2") String param2) {
return "param1 = "+param1;
}
}
For some reason pram1 is null. What am i doing wrong?
No comments:
Post a Comment