【问题标题】:Http Request with adding sql query android带有添加sql查询android的Http请求
【发布时间】:2015-06-18 23:49:31
【问题描述】:

我想要来自 android 中以下链接的 HTTP 请求。我尝试了各种方法将我的 sql 查询添加到我的 URL,但我无法实现。

我认为问题在于 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();
        }
    }

错误

引起:java.lang.IllegalArgumentException:非法字符 在索引 50 处查询:https://query.yahooapis.com/v1/public/yql?q=select * 来自 yahoo.finance.quotes 中的符号 ("MSFT")&format=json&env=store://datatables.org/alltableswithkeys 在 java.net.URI.create(URI.java:730)

【问题讨论】:

    标签: android httprequest


    【解决方案1】:

    将星号更改为“%2A”。星号字符保留用于 URL 中的特殊用途。

    "...select%20%2A%20from%20yahoo....."

    【讨论】:

    • 尝试 query.yahooapis.com/v1/public/…> 时?出现android.os.NetworkOnMainThreadException 之类的错误
    • 代码示例handler.post(new Runnable() { @Override public void run() { try { response = httpclient.execute(new HttpGet("https://query.yahooapis.com/v1/public/yql?q=select%20%2A%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22MSFT%22)&amp;format=json&amp;env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys")); Log.e("response",""+response); } catch (IOException e) { e.printStackTrace(); } } });
    • 请您自己尝试一下,如果您收到回复,然后将示例代码发送给我。Thanxx 进行重播。
    【解决方案2】:

    【讨论】:

    • 我已经尝试过这个query.yahooapis.com/v1/public/…>这对我也不起作用,试试你自己,如果你得到回应,那就给样品。 Thanxxx 重播
    • 上面的链接不能像这样使用Urlquery.yahooapis.com/v1/public/…>?
    • query.yahooapis.com/v1/public/…>?也试试这个。请您自己尝试一下,如果您收到回复,请给我发送示例代码。Thanxxx
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-20
    • 1970-01-01
    相关资源
    最近更新 更多