我已经搜索了两个星期,如何在 Android 上使用 post 发布数据,我到处寻找,尝试了所有解决方案,但它仍然不起作用。现在,我只需要发布一个字符串链,稍后我将不得不发布带有一些字符串链的图片。我的实际代码是:
public String Publication()
{
try
{
Intent intentget = getIntent();
String titre = intentget.getExtras().getString("titre");
String poster = titre +"="+getTableau(_tlab, iNbLignes, iNbCol);
Log.d("reponse","gettableau");
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://tweet.envrac.ch/Publication.php");
Log.d("reponse","url");
List<NameValuePair> pairs = new ArrayList<NameValuePair>(1);
pairs.add(new BasicNameValuePair("LabColler", poster));
Log.d("reponse","pairs");
post.setEntity(new UrlEncodedFormEntity(pairs));
Log.d("reponse","encode");
//bug ici
HttpResponse response = client.execute(post, new BasicHttpContext());
Log.d("reponse","post");
return "reponse = "+response;
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return "erreur";
}
}
希望您能够帮助我。