I want HTTP request from below link in android. I have tried various ways to add my sql query to my URL but I can't make it happen.
I think the problem is with '*' (star) in the URL.
<https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22MSFT%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys>?
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = null;
try {
response = httpclient.execute(new HttpGet("https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol in (\"MSFT\")&format=json&env=store://datatables.org/alltableswithkeys"));
} catch (IOException e) {
e.printStackTrace();
}
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
response.getEntity().writeTo(out);
String responseString = out.toString();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
//..more logic
} else{
//Closes the connection.
try {
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
} catch (IOException e) {
e.printStackTrace();
}
}
Error
Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 50: https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol in ("MSFT")&format=json&env=store://datatables.org/alltableswithkeys at java.net.URI.create(URI.java:730)
Change the asterisk to "%2A". The asterisk character is reserved for special uses in URLs.
"...select%20%2A%20from%20yahoo....."