2012-04-19 7 views
0
public void callService() 
    { 
     HttpPost postMethod = new HttpPost(url); 
     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 

     nameValuePairs.add(new BasicNameValuePair("latitude",latitude)); 
     nameValuePairs.add(new BasicNameValuePair("longitude",longitude)); 
     try { 
      postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
     } catch (UnsupportedEncodingException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 
     DefaultHttpClient hc = new DefaultHttpClient(); 

     HttpResponse response = null; 
     try { 
      response = hc.execute(postMethod); // not able to execute the statement. 
     } catch (ClientProtocolException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     HttpEntity entity = response.getEntity(); 

     if (entity != null) 
     { 
       InputStream inStream = null; 
       try { 
        inStream = entity.getContent(); 
       } catch (IllegalStateException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } catch (IOException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
       result= convertStreamToString(inStream); 
       Log.i("---------------- Result",result); 
     } 
    } // end callService() 

を呼び出している間は、上記と同じのためのコードである、 私はコードは、この文の後に終了していることが判明しましたコード:応答= hc.execute(postMethod); この文脈でのヘルプは非常に高く評価されます。 ありがとうございます。あなたの投稿のタイトルに基づいてHTTP GETメソッドエラーをRESTのWCFサービス私たちは、私のAndroidデバイスからWCF RESTサービスを呼び出すようにしようとしている

+0

実行が停止するとログには何が表示されますか? –

+0

"実行停止"接続試行がタイムアウトになることがあります。あなたはアンドロイドデバイスからサーバーにアクセスできますか? – kenota

答えて

0

だけGETすることができますRESTサービスへのPOSTを送信していますか?

関連する問題