Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"username":"tenant@test.org", "password":"tenant"}' 'http://URL/api/auth/login'
  2.  
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.activity_main);
  7. PostRequest();
  8. }
  9.  
  10. private void PostRequest(){
  11.  
  12.  
  13.  
  14. Thread t = new Thread(new Runnable() {
  15. @Override
  16. public void run() {
  17.  
  18. HttpParams myParams = new BasicHttpParams();
  19.  
  20. HttpConnectionParams.setSoTimeout(myParams, 10000);
  21. HttpConnectionParams.setConnectionTimeout(myParams, 10000); // Timeout
  22.  
  23. DefaultHttpClient httpClient = new DefaultHttpClient(myParams);
  24.  
  25.  
  26. HttpPost httpPost = new HttpPost("http://url/api/auth/login");
  27.  
  28. httpPost.addHeader("Accept: application/json", "Content-Type: application/json");
  29.  
  30. List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
  31. nameValuePair.add(new BasicNameValuePair("username", "user"));
  32. nameValuePair.add(new BasicNameValuePair("password", "pass"));
  33.  
  34. try {
  35. httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
  36. } catch (UnsupportedEncodingException e) {
  37. e.printStackTrace();
  38. }
  39.  
  40.  
  41. //making POST request.
  42. try {
  43. HttpResponse response = httpClient.execute(httpPost);
  44. // write response to log
  45. System.out.println("LOG:" + response.toString());
  46. } catch (ClientProtocolException e) {
  47. // Log exception
  48. e.printStackTrace();
  49. } catch (IOException e) {
  50. // Log exception
  51. e.printStackTrace();
  52. }
  53. }
  54. });
  55. t.start();
  56.  
  57.  
  58. }
  59.  
  60. 09-24 11:53:47.080 3781-3867/com.example.david.auth W/DefaultRequestDirector: Authentication error: Unable to respond to any of these challenges: {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement