gpt4 book ai didi

java - Android http请求POST

转载 作者:行者123 更新时间:2023-12-01 05:15:24 24 4
gpt4 key购买 nike

我正在构建一个简单的 Android 应用程序,它将 http post 请求发送到此站点 http://www.ap-ljubljana.si/vozni_red2/VR2.php然后根据post请求得到适当的响应。问题是我的应用程序没有得到与浏览器相同的响应。有什么想法吗?

java文件

`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请求

http://i45.tinypic.com/zvqww7.jpg

最佳答案

您的 APP 请求中缺少 cookie 信息。这可能会产生问题。我认为,一些服务器端调试可以解决此问题。

关于java - Android http请求POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11293656/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com