2012-03-23 48 views
1

我嘗試使用外部網站獲取數據,但我似乎得到的是整個網站的HTML源代碼。事實上,它不處理我傳遞給它的參數。 該網站是http://www.siirretytnumerot.fi/,如果我將QueryServerlet添加到鏈接的末尾,我只是得到鏈接的源代碼的簡短結構,沒有任何結果。我也試過使用HttpPost和Get仍然一樣。請有人可以告訴我,問題是網站不能用於資源的目的? 請給我任何意見或建議。 我正在使用的代碼是這樣的。並注意我有一個try和catch子句圍繞此代碼。如何使用HttpPost或從本網站獲取正文結果?

HttpClient client = new DefaultHttpClient(); 

     String postURL = "http://www.siirretytnumerot.fi/";//if I add QueryServlet to the end it just gives a response with the html structure 
     BufferedReader in=null; 
     String data=null; 
     HttpPost post = new HttpPost(postURL); 


      List<NameValuePair> params = new ArrayList<NameValuePair>(); 

      params.add(new BasicNameValuePair("PREFIX", "044")); 
      params.add(new BasicNameValuePair("NUMBER", "9782231")); 
      params.add(new BasicNameValuePair("LANGUAGE", "English")); 
      params.add(new BasicNameValuePair("Submit", "Search")); 

      UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8); 

      post.setEntity(ent); 
      HttpResponse responsePOST = client.execute(post); 


      in=new BufferedReader(new InputStreamReader(responsePOST.getEntity().getContent()));  
      StringBuffer sb=new StringBuffer(""); 
      String l=""; 
      String nl=System.getProperty("line.separator"); 
      while((l=in.readLine())!=null){ 
       sb.append(l+nl); 
      } 
      in.close(); 
      data=sb.toString(); 
      list.add(data); 
      datalist=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list); 
      ml.setAdapter(datalist); 

這是輸出我從響應得到

<img src="QueryServlet?ID=457016727131196340&amp;STRING=QIHfqzk16uj6adStbdzyaqMjYwaokhP1Zq1Tlz%2BjL4YQ7tRne4RdxwCcvcJKiZWvvsTXcpqHxcDplE9LVExKGg==" /> 

回答

2

嘗試這樣的:

String postURL = "http://www.siirretytnumerot.fi/QueryServerlet"; 
... 
params.add(new BasicNameValuePair("Submit2", "Clear")); 
... 
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params); 
+0

感謝現在的工作,但我得到的迴應是,我已經添加到圖像源上面的代碼。你能告訴我,如果有任何我可以解碼該圖像源的字符串部分? – 2012-03-23 11:44:04

+0

我不知道 – Caner 2012-03-23 11:44:54

+0

謝謝我的讚賞。 – 2012-03-23 11:53:11