Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"username":"tenant@test.org", "password":"tenant"}' 'http://URL/api/auth/login'
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- PostRequest();
- }
- private void PostRequest(){
- Thread t = new Thread(new Runnable() {
- @Override
- public void run() {
- HttpParams myParams = new BasicHttpParams();
- HttpConnectionParams.setSoTimeout(myParams, 10000);
- HttpConnectionParams.setConnectionTimeout(myParams, 10000); // Timeout
- DefaultHttpClient httpClient = new DefaultHttpClient(myParams);
- HttpPost httpPost = new HttpPost("http://url/api/auth/login");
- httpPost.addHeader("Accept: application/json", "Content-Type: application/json");
- List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
- nameValuePair.add(new BasicNameValuePair("username", "user"));
- nameValuePair.add(new BasicNameValuePair("password", "pass"));
- try {
- httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- //making POST request.
- try {
- HttpResponse response = httpClient.execute(httpPost);
- // write response to log
- System.out.println("LOG:" + response.toString());
- } catch (ClientProtocolException e) {
- // Log exception
- e.printStackTrace();
- } catch (IOException e) {
- // Log exception
- e.printStackTrace();
- }
- }
- });
- t.start();
- }
- 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