2012-03-23 82 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