K
K
Kitoved2016-11-23 20:55:10
Android
Kitoved, 2016-11-23 20:55:10

I need to send a POST from android to the site, am I doing it right?

there is a link

http://ваывыаы.ru/js/main.js.php?act=zve%20$_POST[%27nickname%27]%20$_POST[%27text%27]%20==%20%20$_POST[%27music%27]

you need to send hello with 3 parameters nickname, text, music.
as I understand it, I need to send a POST request
in the asyncTask thread, I do it, but nothing works,
help me find the right solution or fix the error.
@Override
      protected String doInBackground(Void... urls) {
  
        
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("http://выфвфывфыв.ru/js/main.js.php");
        
           try {
             
            
             List pairs = new ArrayList();
             nick = editText1.getText().toString();
             text = editText2.getText().toString();
             music = editText3.getText().toString();
              pairs.add(new BasicNameValuePair("nickname", nick ));
              pairs.add(new BasicNameValuePair("text", text));
              pairs.add(new BasicNameValuePair("music", music));
              httppost.setEntity(new UrlEncodedFormEntity(pairs));
              HttpResponse response = httpclient.execute(httppost);
              responseString = EntityUtils.toString(response.getEntity());
              
              
                   } catch (Exception e) {}
           
      return responseString;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kitoved, 2017-02-01
@Kitoved

In general, I solved my problem.
This code helped, who can explain in Russian what kind of apach is and what it does. I understand this because of https and some certificates of conformity.

HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

        DefaultHttpClient client = new DefaultHttpClient();
        SchemeRegistry registry = new SchemeRegistry();
        SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
        socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
        registry.register(new Scheme("https", socketFactory, 443));
        SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
        DefaultHttpClient httpclient = new DefaultHttpClient(mgr, client.getParams());
        HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);

final String url = "http://выфвфывфыв.ru/js/main.js.php";
        HttpPost httppost = new HttpPost(url);

O
Oleg Gamega, 2016-11-23
@gadfi

1. check if you understood correctly what and where to send through any rest client (I use postman)
2. use retrofit (I haven’t used HttpClient for three years, which is what I wish you)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question