Guest User

Untitled

a guest
Jan 13th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. How can I access the data which is sent by POST method (Android) in the jersey POST annotation?
  2. public class TestClient extends Activity {
  3.  
  4. @Override
  5. public void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.layout_main);
  8. HttpClient httpclient = new DefaultHttpClient();
  9. HttpPost httppost = new HttpPost("myURL");
  10.  
  11. try {
  12.  
  13. List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
  14. nameValuePairs.add(new BasicNameValuePair("user", "user1"));
  15. nameValuePairs.add(new BasicNameValuePair("password", "password1"));
  16. httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  17.  
  18. httpclient.execute(httppost);
  19.  
  20. } catch (ClientProtocolException e) {
  21.  
  22. } catch (IOException e) {
  23.  
  24. }
  25.  
  26. }
  27.  
  28. }
  29.  
  30. @Path("test")
  31. public class Test {
  32. @GET
  33. @Produces(MediaType.TEXT_PLAIN)
  34. public String respondAsReady() {
  35. return "Running";
  36. }
  37.  
  38. @POST
  39. @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  40. @Produces(MediaType.TEXT_PLAIN or other?)
  41.  
  42. //Here I'd like the program to post (with System.out.println) the data to the console which is uploaded by the client using the POST method.
  43.  
  44.  
  45. }
  46. }
  47.  
  48. @POST
  49. @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  50. public void themethodname(@FormParam("user") String user,
  51. @FormParam("password") String password) {
  52. System.out.println("Username: "+user+", "+"Password: "+password);
  53. }
Add Comment
Please, Sign In to add comment