Commits

Anonymous committed ca8bff8

httpclientが使えるように修正
manifestのpermission追加

  • Participants
  • Parent commits 49233fb

Comments (0)

Files changed (6)

File AndroidManifest.xml

 	<data android:mimeType="image/jpeg"></data>
 </intent-filter>
 </activity>
+
+
 </application>
 
+<uses-permission android:name="android.permission.INTERNET"/>
 
 </manifest> 

File bin/androizou.apk

Binary file modified.

File bin/classes.dex

Binary file modified.

File bin/org/homelinux/sheephead/androizou/Upload.class

Binary file modified.

File bin/resources.ap_

Binary file modified.

File src/org/homelinux/sheephead/androizou/Upload.java

 
 import java.io.File;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.mime.MultipartEntity;
 import org.apache.http.entity.mime.content.FileBody;
+import org.apache.http.entity.mime.content.StringBody;
 import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
+
 import android.app.Activity;
 import android.content.Intent;
 import android.database.Cursor;
+//import android.net.Credentials;
 import android.net.Uri;
 import android.os.Bundle;
 import android.util.Log;
 
+
+import org.apache.http.auth.Credentials;
+
+
+
+
+
 public class Upload extends Activity {
    private static final String TAG = "Logact";
    private String filepath;
                 filepath = csr.getString(csr.getColumnIndexOrThrow("_data"));
                 Log.d(TAG,"data=" + csr.getString(csr.getColumnIndexOrThrow("_data")));
                 csr.moveToNext();
+            }
                
-        DefaultHttpClient client = new DefaultHttpClient();
-//      送り先 先は先で適当にPHPで処理しておく
-        HttpPost post = new HttpPost("http://192.168.11.111/hoge.php");
-        MultipartEntity entity = new MultipartEntity();
-        post.setEntity(entity);
-//      ↓送りたいファイルのセット
-        FileBody fileBody = new FileBody(new File(filepath));
-        entity.addPart("file", fileBody);
-//      送信
-        try {
-            client.execute(post);
-        } catch (ClientProtocolException e) {
-//            Log.d(TAG,"post Protocol error");
-        } catch (IOException e) {
-//            Log.d(TAG,"post IO error");
-        }
+       DefaultHttpClient client = new DefaultHttpClient();
+    // 送り先 先は先で適当にPHPで処理しておく
+           
+       //HttpPost post = new HttpPost("http://api.photozou.jp/rest/photo_album");
+       HttpPost post = new HttpPost("http://api.photozou.jp/rest/photo_add"); 
+      
+
+       URI posturi = post.getURI();
+       
+       client.getCredentialsProvider().setCredentials(
+    		   new AuthScope(posturi.getHost(), posturi.getPort()),
+    		   new UsernamePasswordCredentials("mail","pass"));
+    
+       MultipartEntity entity = new MultipartEntity();
+       post.setEntity(entity);
+       //↓送りたいファイルのセット
+       FileBody fileBody = new FileBody(new File(filepath),"image/jpeg");
+       entity.addPart("photo", fileBody);
+       try {
+    	   entity.addPart("album_id", new StringBody("134703"));
+       } catch (UnsupportedEncodingException e1) {
+    	   // 自動生成された catch ブロック
+    	   e1.printStackTrace();
+       }
+		
         
- 
-        
-        
-//          File f = new File("/path/fileToUpload.txt");
-//  HttpRequest request = new HttpRequest("http://host/some_path");
-//  Part[] parts = {
-//      new StringPart("param_name", "value"),
-//      new FilePart(f.getName(), f)
-//  };
-//  filePost.setEntity(
-//      new MultipartRequestEntity(parts, filePost.getParams())
-//      );
-//  HttpClient client = new HttpClient();
-//  int status = client.executeMethod(filePost);
+     //送信
+       try {
+           HttpResponse res = client.execute(post);
+           String strres = EntityUtils.toString(res.getEntity());
+           Log.d(TAG,strres);
+       } catch (ClientProtocolException e) {
+           Log.d(TAG,"post Protocol error");
+       } catch (IOException e) {
+    	   
 
-        
-        //HttpClient httpClient = new DefaultHttpClient();
-        //HttpPost post = new HttpPost(URL);
-        //MultipartEntity entity 
+           Log.d(TAG,"io error");
+       } 
         
 //        	private void SetIDAndPass( boolean bCreate){
 //		updateButton.setClickable(false);