2011-07-13 26 views
0

XMLファイルを使用してサーバーにリクエストを送信しています。それに応じて私は回答を得なければならない。しかし、私はファイルがURLに例外が見つかりませんを取得しています。私のコードはここにあります。XMLでサーバー上のデータを送信する方法、および応答を受信する方法

public InputStream testPost(String xmlString,URL url) 
{ 
    try 
    { 
     httpClient = new DefaultHttpClient(); 
     connection = (HttpURLConnection)url.openConnection(); 
     connection.setDoInput(true); 
     connection.setDoOutput(true); 
     connection.setUseCaches(false); 
     connection.setRequestMethod("POST"); 
     connection.setRequestProperty("Content-Type", "text/xml"); 
     DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); 
     outputStream.writeBytes(xmlString); 
     outputStream.flush(); 
     isResponse = (InputStream) connection.getInputStream(); 
    } 
    catch(UnknownHostException e) 
    { 
     Log.e("Failure","Network Failure"+e.toString()); 
    }  
    catch(SocketException e) 
    { 
     Log.e("Failure--","Network Failure"+e.toString()); 
    } 
    catch(Exception e) 
    { 
     e.printStackTrace(); 
    } 
    return isResponse; 
} 



public void addLocation() 
{ 
    try 
    { 
     String strAddLocation = "<useraccount>" + 
     "<id>"+1+"</id>" +"<location>"+ 
     "<geocode>"+77.254188+","+28.692365+"</geocode>" + 
     "<address>3523 16th street</address>" + 
     "<city>Hyd</city>" + 
     "<state>NY</state>" + 
     "<zip>"+11006+"</zip>" + 
     "<country>USA</country>" + 
     "<is_primary>"+false+"</is_primary>" + 
     "</location>"+"</useraccount>"; 

     Log.i("this", strAddLocation); 

     urlPost = new UrlPost(); 

     addLocationInputStream= urlPost.testPost(strAddLocation, new URL(AppConstants.HOST_URL+AppConstants.ADD_LOCATION+1)); 
     if(addLocationInputStream!= null) 
     { 
      Log.i("the output is coming hare", "add location"); 
     } 
     InputStreamReader reader = new InputStreamReader(addLocationInputStream); 
     StringBuilder buf = new StringBuilder(); 
     char[] cbuf = new char[ 2048 ]; 
     int num; 
     while (-1 != (num=reader.read(cbuf))) 
     { 
      buf.append(cbuf, 0, num); 
     } 
     String result = buf.toString(); 
      System.err.println("\nResponse from server after delete = " + result); 
     reader.close(); 
      Log.i("reponce","\nResponse from server after delete = " + result); 
    } 

     catch(Exception ee) 
     { 
     Log.i("the error is here", ee.toString()); 
     } 

} 

答えて

0

はあなたAndroidMainfest.xmlファイルにマニフェストタグとアプリケーションタグの外側の内側

<uses-permission android:name="android.permission.INTERNET" /> 

を追加したことがありますか?

+0

ええ..私はすべてのアクセス許可をMainfest.xmlファイルに追加しました。 – Kamal

関連する問題