簡體   English   中英

Android http請求POST

[英]Android http request POST

我正在構建一個簡單的android應用程序,該應用程序將http發布請求發送到此網站http://www.ap-ljubljana.si/vozni_red2/VR2.php ,然后根據發布請求獲取適當的響應。 問題是我的應用程序無法獲得與瀏覽器相同的響應。 有什么想法嗎?

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發布請求

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

您的APP請求中缺少cookie信息。可能是造成問題。某些服務器端調試可以解決此問題。

我認為您沒有點擊確切的URL,因為您點擊的URL不是API,即AFAIT,因為這是指向它的網頁URL。

在瀏覽器中,當您執行其他任務時,還有其他API鏈接正在執行任務,並且您會獲得正確的響應,因為這樣構建的網頁可以幫助您了解響應結果,但是當您在此鏈接上執行操作時,它實際上返回上述php鏈接的內容,而主要工作由其他API鏈接完成。

如果我錯了,請告訴我,以便為您提供幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM