2013-04-07 14 views
1

我需要從我的應用程序傳遞3下拉值到網站鏈接http://www.way2franchise.com/ 說:廣告和媒體,選擇投資,選擇狀態。是我的3個值。
我需要傳遞到搜索過濾器鏈接: http://www.way2franchise.com/search/filter_franchise傳遞數據到服務器並接收它

P.S:我不能發佈超過2個鏈接,因爲受到了stackoverflow的限制。
在討論有兩個鏈接:
1.網站鏈接
2.搜索過濾器鏈接。

public class DatafetchingActivity extends Activity { 

TextView result; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    result = (TextView) findViewById(R.id.result); 

    BufferedReader bufferedReader = null; 
    HttpClient httpClient = new DefaultHttpClient(); 
    HttpPost request = new HttpPost("http://www.way2franchise.com/search/filter_franchise"); 
    List<NameValuePair> postParameters = new ArrayList<NameValuePair>(); 
    postParameters.add(new BasicNameValuePair("p", "advertisement_and_media")); 
    postParameters.add(new BasicNameValuePair("q", "Select Industry")); 
    postParameters.add(new BasicNameValuePair("r", "Select Industry")); 


    try { 
     UrlEncodedFormEntity entity = new UrlEncodedFormEntity(
       postParameters); 
     request.setEntity(entity); 

     HttpResponse response = httpClient.execute(request); 

     bufferedReader = new BufferedReader(new InputStreamReader(response 
       .getEntity().getContent())); 
     StringBuffer stringBuffer = new StringBuffer(""); 
     String line = ""; 
     String LineSeparator = System.getProperty("line.separator"); 
     while ((line = bufferedReader.readLine()) != null) { 
      stringBuffer.append(line + LineSeparator); 
     } 
     bufferedReader.close(); 

     result.setText(stringBuffer.toString()); 

     Toast.makeText(DatafetchingActivity.this, "Finished", 
       Toast.LENGTH_LONG).show(); 

    } catch (ClientProtocolException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     Toast.makeText(DatafetchingActivity.this, e.toString(), 
       Toast.LENGTH_LONG).show(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     Toast.makeText(DatafetchingActivity.this, e.toString(), 
       Toast.LENGTH_LONG).show(); 
    } finally { 
     if (bufferedReader != null) { 
      try { 
       bufferedReader.close(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
    } 

} 

} 現在,此輸出爲搜索filter.Its的整個結果相同的輸出,如同我複製並粘貼的搜索過濾器鏈接。

但這不是我想要的。

我需要的是,如果我打開鏈接(而不是搜索過濾器鏈接),並選擇廣告和媒體選項,選擇投資,選擇狀態。我應該只根據傳遞的選項值得到結果。

+0

我一無所知機器人編程,但你知道你有'「選擇行業」'指定兩次當您添加項目到'postParameters'列表? – Tinsa 2013-04-07 12:48:49

+1

@MoonSire這是一個領域,所以這裏沒有問題。 – 2013-04-07 13:22:46

回答

1

下面的代碼:


    postParameters.add(new BasicNameValuePair("p", "advertisement_and_media")); 
    postParameters.add(new BasicNameValuePair("q", "Select Industry")); 
    postParameters.add(new BasicNameValuePair("r", "Select Industry")); 
這裏有三個名稱值對,即P,Q,r.These是它在你設置的鍵「P」送server.So接收到的值的鑰匙, 「q」,「r」數據將在服務器端用這些鍵/值對接收。

希望我回答你的問題。

相關問題