我必须将一些数据发布到一个url,这是我的代码。之后这个服务器必须将我重定向到一个新的URL,但是hpw我能在android中得到它吗?
public void postData() {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "data"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
} 发布于 2011-07-06 14:22:24
您可以使用$_server在php中获取url并回显该字符串。
不是使用
HttpResponse response = httpclient.execute(httppost);
使用以下代码
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String ResponseBody = httpClient.execute(httppost, responseHandler);现在,响应正文字符串包含从php服务器回显的url。
https://stackoverflow.com/questions/6591982
复制相似问题