私は、アンドロイドウェブサービスを呼び出すロジックを書いて、いくつかのパラメータを渡しました。問題は、私がXMLとして取得するエラーメッセージを返すクエリを送信するときです。私が呼びたいURLは http://192.168.1.10:8080/ymaws/resources/restaurantcityid=33498&areanm=vasant vihar ですが、エラーが出ます。コードは以下の通りです。 Plzはこのrestfull webserviceをURIにスローするエラーが発生しました
String list = null;
restaurantnames=new ArrayList<String>();
areanames=new ArrayList<String>();
restaurantidlist=new ArrayList<String>();
final HttpClient client=new DefaultHttpClient();
String url = "http://192.168.1.10:8080/ymaws/resources/restaurant?cityid="+cityid+"&areanm="+area.getSelectedItem().toString();
String encodedurl = null;
try
{
encodedurl = URLEncoder.encode(url,"UTF-8");
}
catch (UnsupportedEncodingException e1)
{
e1.printStackTrace();
}
Log.i("TEST", encodedurl);
final HttpGet req=new HttpGet(encodedurl);
HttpResponse httpResponse;
try {
httpResponse=client.execute(req);
HttpEntity entity = httpResponse.getEntity();
Log.i("entity", entity.toString());
if (entity != null)
{
InputStream instream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
StringBuilder sb = new StringBuilder();
String line = null;
try
{
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
instream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
// Closing the input stream will trigger connection release
list= sb.toString();
Log.i("list xml is", list.toString());
私はこのように書いて、再び強制終了しました。私はもう一度それをやっていると思う。
samir
友達が解決策を得ました。実際の問題は、スペースを含む最後のパラメータを渡していたことでした。それはエラーを投げていたので、私はそれらのスペースを削除する方法を検討する必要があります。%20は方法ですが、 – samir