I was wondering if anyone can tell me why I get a bad request error when I try to execute a RESTfull service using Retrofit
Error: Invalid HTTP / 1.1 400 Request
Here are my two classes:
RetrofitInterface:
public class RetrofitInterface {
private static StockApiInterface sStockService;
public static StockApiInterface getStockApiClient() {
if (sStockService == null) {
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("http://query.yahooapis.com/v1/public")
.build();
sStockService = restAdapter.create(StockApiInterface.class);
}
return sStockService;
}
public interface StockApiInterface {
@GET("/yql")
void listQuotes(@Query("q") String query,Callback<Stock> stockInfo);
}
}
Asyntask inside MainActivity
public class extraThread extends AsyncTask<Void, Void, Void>{
@Override
protected Void doInBackground(Void... params) {
RetrofitInterface.getStockApiClient().listQuotes("select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(\"AIB.IR\")%0A%09%09&format=json&diagnostics=true&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=", new Callback<Stock>() {
@Override
public void failure(RetrofitError arg0) {
arg0.printStackTrace();
}
@Override
public void success(Stock arg0, Response arg1) {
}
});
}
}
The result is always a failure. Initially, I thought the problem was that Retrofit, which was built into gson converter, had a problem converting the response to the stock object, since I got the answer "Retrofit.retrofiterror". However, the “Bad Request” response made me think that the problem was in the url for the api. Here is my desired response url:
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22AIB.IR%22)%0A%09%09&format=json&diagnostics=true&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=
- , ? , . , ?
Stock. - POJO
public class Stock {
@Expose
private Query query;
public Query getQuery() {
return query;
}
public void setQuery(Query query) {
this.query = query;
}
}
.