2011-12-29 17 views
1

私はアンドロイドで働いています。私は私のアプリケーションとfoursquareを統合したい。ファイルが見つかりませんでした

場所でのチェックイン機能。私はこの次のコードを使用しています: -

URL url = new URL("https://api.foursquare.com/v2/checkins/add/"); 

       URLConnection conn = url.openConnection(); 
       conn.setDoOutput(true); 
       OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); 
       wr.write(data); 
       wr.flush(); 

       BufferedReader rd = new BufferedReader(new 

InputStreamReader(conn.getInputStream())); 
       String line; 
       while ((line = rd.readLine()) != null) { 

      } 

これはファイルが見つかりません例外を生成しています。私がやった間違いを助けてください。

ありがとうございます。

+0

からデータを書き込むには、このURLについてあなたは確かですか?ファイルがありますか? –

+0

ブラウザでURLを確認してください。ファイルはリンク上に実際に存在しますか? –

答えて

1

アプローチに

読み取りと次のように試してみて、URL

void readAndWriteFromWeb(){ 

     //make connection 

     URL url = new URL("https://api.foursquare.com/v2/checkins/add/"); 

     HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); 
     httpURLConnection.setRequestMethod("POST"); 
     httpURLConnection.setDoOutput(true); 
     httpURLConnection.setDoInput(true); 
     httpURLConnection.setAllowUserInteraction(true); 
     httpURLConnection.setRequestProperty("Connection", "keep-alive"); 
     httpURLConnection.setRequestProperty("ConnectionTimeout", "12000"); 
     httpURLConnection.setRequestProperty("Content-Length", "" + request.length); 

     //write data 
     OutputStream out = httpURLConnection.getOutputStream(); 
     out.write(request); 
     out.flush(); 
     //Log.e("Request URL "+url, "Request Data "+request); 

    //read data 
     InputStream inputStream = httpURLConnection.getInputStream(); 
     int length = httpURLConnection.getContentLength(); 
     //Log.e("Content Length", "" + length); 

     int readLength = 0; 
     int chunkSize = 1024; 
     int readBytes = 0; 
     byte[] data = new byte[chunkSize]; 

     StringBuilder builder = new StringBuilder(); 

     while((readBytes = inputStream.read(data)) != -1){ 
      builder.append(new String(data,0,readBytes).trim()); 
      readLength += readBytes; 

      //Release the memory. 
      data = null; 
      //Check the remaining length 
      if((length - readLength) < chunkSize){ 
       if((length - readLength) == 0){ 
        break; 
       } 
       data = new byte[((length) - readLength)]; 
      }else{ 
       data = new byte[chunkSize]; 
      } 
     } 
    } 
+0

あなたは「要請」を使って何ですか?それは未定義です。 –

関連する問題