1

我正在尝试在我的 Android 应用程序中使用Foursquare 的搜索场所。我的 URL 必须正确,它在浏览器中工作正常,但在我的 Android 应用程序中,我得到一个 IOException: java.io.FileNotFoundException。我猜我的 HTTP 请求有问题,但我不知道是什么问题。你能帮我吗?

new Thread() {
@Override 
public void run() {
    Looper.prepare();   

    try 
    {
        URL url = new URL(  FSQR_URL + 
                            "venues/search?ll=" + Float.toString(latitude) + "," + Float.toString(longitude) + 
                            "&client_id=" + FSQR_CLIENT_ID + 
                            "&client_secret=" + FSQR_CLIENT_SECRET + 
                            "&v=" + timeMilisToString(System.currentTimeMillis()));

        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.setDoInput(true);
        urlConnection.setDoOutput(true);
        urlConnection.connect();

        String responseBody     = streamToString(urlConnection.getInputStream());

        try 
        {
            JSONObject response1 = new JSONObject(responseBody);
            JSONObject response2 = new JSONObject(response1.getString("response"));
            setSearch(new JSONArray(response2.getString("venues")));
        } 
        catch (JSONException e) 
        {
            mResult.onError(e.toString());
        } 
    } 
    catch (ClientProtocolException e) 
    {
        mResult.onError(e.toString());   
    } 
    catch (IOException e) 
    {
        mResult.onError(e.toString());
    }   
}         

}。开始();

4

0 回答 0