继续存在AVD和提琴手问题

时间:2012-10-02 22:40:07

标签: android fiddler

下面的代码有两行建议用来解决fiddler无法在AVD模拟器中看到帖子的问题。如果没有这两行,帖子就会成功,但是小提琴手看不到它。使用这两行后,该帖子在大约10分钟后返回,并带有I / O异常。

    public HttpResponse postData() 
{ 
    // Create a new HttpClient and Post Header 

    HttpClient httpclient = new DefaultHttpClient(); 
    HttpPost httppost = new HttpPost("http://www.yoursite.com/api/GETTrafficDirector"); 
    HttpResponse response = null; 

    //do these two lines so fiddler can see post when debugging
    HttpHost proxy = new HttpHost("192.168.2.8", 8888); 
    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); 


    try { 
            // Add your data 
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
            nameValuePairs.add(new BasicNameValuePair("id", "12345")); 
            nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!")); 
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

            // Execute HTTP Post Request 
            response = httpclient.execute(httppost); 

        } 
    catch (ClientProtocolException e) 
    { 
        // TODO Auto-generated catch block 
    } 
    catch (IOException e) 
    { 
        // TODO Auto-generated catch block 
    } 
    return response;

0 个答案:

没有答案