我正在构建一个简单的 android 应用程序,它向这个站点http://www.ap-ljubljana.si/vozni_red2/VR2.php发送一个 http post 请求,然后根据 post 请求获得适当的响应。问题是我的应用程序没有得到与浏览器相同的响应。任何想法为什么?
文件
`HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.ap-ljubljana.si/vozni_red2/VR3.php");
try{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("VSTOP_ID", "1"));
nameValuePairs.add(new BasicNameValuePair("IZSTOP_ID","1"));
nameValuePairs.add(new BasicNameValuePair("btnNext", "Naprej"));
httppost.setHeader("Cache-Control", "max-age=0");
httppost.setHeader("Origin", "http://www.ap-ljubljana.si");
httppost.setHeader("Referer", "http://www.ap-ljubljana.si/vozni_red2/VR2.php?DATUM="+datum+"&VSTOP_IME=Vstop...&IZSTOP_IME=Izstop...");
httppost.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
httppost.setHeader("DNT", "1");
httppost.setHeader("Accept-Encoding", "gzip,deflate,sdch");
httppost.setHeader("Accept-Language", "sl-SI,sl;q=0.8,en-GB;q=0.6,en;q=0.4");
httppost.setHeader("Accept-Charset", "ISO-8859-2,utf-8;q=0.7,*;q=0.3");
//httppost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
return httpclient.execute(httppost);
}
catch (ClientProtocolException e){
return null;
}
catch (IOException e){
return null;
}`
浏览器的http post请求