Answer the question
In order to leave comments, you need to log in
How to send a POST request on an Android device?
Good day. I need to send a POST request to the server and everything seems to be clear, but the problem is that all the data that was sent to me for it is just this picture:
I first tried to implement it in the usual way:
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://televizera.net/sms/");
try {
StringEntity stringEntity = new StringEntity("act=createOrder&phone=79154508472&place=1&pays=1m2");
post.setEntity(stringEntity);
post.setHeader("Content-type", "application/xhtml+xml");
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
line = "";
while ((line = rd.readLine()) != null) {
line += line;
}
} catch (IOException e) {
e.printStackTrace();
}
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://televizera.net/sms/");
try {List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair(4);
nameValuePairs.add(new BasicNameValuePair("act","createOrder"));
nameValuePairs.add(new BasicNameValuePair("phone","06620"));
nameValuePairs.add(new BasicNameValuePair("place","1"));
nameValuePairs.add(new BasicNameValuePair("pays","1m2"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
line = "";
while ((line = rd.readLine()) != null) {
line += line;
}
} catch (IOException e) {
e.printStackTrace();
}
Answer the question
In order to leave comments, you need to log in
What error does it give on exit? I suspect that "NetworkOnMainThreadException"
Did you forget to put it in the manifest?
uses-permission android:name="android.permission.INTERNET"
uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question