1

I am trying to get a csv file from url. But I am getting error as

java.lang.IllegalArgumentException : Illegal Character in query at index 43 :

Same code is working for other url.

try
{
    String result = "";
    HttpClient httpClient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    HttpGet httpGet = new HttpGet("http://in.finance.yahoo.com/d/quotes.csv?s=^BSESN+^NSEI +LML.NS +LT.NS +RELIANCE.NS +HUL.BO+ONGC.NS+GOLDBEES.BO +ITC.NS +Acc.NS+UNITECH.NS +SPANCO.BO +OCL.NS +LAKSHMIO.BO+POWERGRID.BO+PACIF.BO+COALINDIA.NS+SATYAMCOM.NS+Bhel.ns+SBIN.NS+Plethico.ns+COLPAL.NS+USHAMART.NS+MTNL.NS +RUCHINFRA.NS&f=nl1oc1ghpvjk");
    HttpResponse response = httpClient.execute(httpGet, localContext);
    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    try
    {
        StringBuffer sb = new StringBuffer();
        String line;
        while((line = reader.readLine())!=null)
        {
            String rowData[] = line.split(",");
            sb.append("\n"+rowData[0]);
        }
        t.setText(sb.toString());
    }
    catch (Exception e) {
        // TODO: handle exception
    }
} catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Thanks in advance..

Archana
  • 101
  • 2
  • 9

1 Answers1

0

I guess there might be some unencoded symbols in your url, try encoding your string it before passing it as argument:

HttpGet httpGet = new HttpGet(Uri.encode("http://in.finance.yahoo.com/d/quotes.csv?s=^BSESN+^NSEI +LML.NS +LT.NS +RELIANCE.NS +HUL.BO+ONGC.NS+GOLDBEES.BO +ITC.NS +Acc.NS+UNITECH.NS +SPANCO.BO +OCL.NS +LAKSHMIO.BO+POWERGRID.BO+PACIF.BO+COALINDIA.NS+SATYAMCOM.NS+Bhel.ns+SBIN.NS+Plethico.ns+COLPAL.NS+USHAMART.NS+MTNL.NS +RUCHINFRA.NS&f=nl1oc1ghpvjk"));
Vladimir
  • 9,683
  • 6
  • 36
  • 57