[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
String postUrl = "http://www.sample.com/post.php";
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(postUrl);
MultipartEntity entity = new MultipartEntity();
try {
entity.addPart("name", new StringBody("Name"));
entity.addPart("type", new StringBody("Type1"));
post.setEntity(entity);
HttpResponse response = httpClient.execute(post);
int status = response.getStatusLine().getStatusCode();
...(略)
String postUrl = "http://www.sample.com/post.php";
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(postUrl);
MultipartEntity entity = new MultipartEntity();
try {
File file = new File(imagePath);
entity.addPart("image", new FileBody(file.getAbsoluteFile()));
post.setEntity(entity);
HttpResponse response = httpClient.execute(post);
int status = response.getStatusLine().getStatusCode();
...(略)
//ギャラリーの画像を選択したら
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
isOnLoading = true;
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_PICK_CONTACT) {
if (data != null) {
imageUri = data.getData();
Thread thr = new Thread(reqUpload);
thr.start();
}
}
}
}
//画像をPOSTする
private Runnable reqUpload = new Runnable() {
@Override
public void run () {
String resp = null;
String postUrl = "http://www.sample.com/post.php";
InputStream inputStream = getContentResolver().openInputStream(imageUri);
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(postUrl);
MultipartEntity entity = new MultipartEntity();
try {
InputStreamBody streamBody = new InputStreamBody(inputStream, "imagename");
entity.addPart("image", streamBody);
post.setEntity(entity);
HttpResponse response = httpClient.execute(post);
int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_OK){
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
response.getEntity().writeTo(oStream);
resp = oStream.toString();
} else {
Log.v("ERR","response status:" + String.valueOf(status));
}
} catch(IOException e) {
Log.v("ERR","msg:" + e.getMessage());
}
}
};
String postUrl = "http://www.sample.com/post.php";
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(postUrl);
MultipartEntity entity = new MultipartEntity();
try {
entity.addPart("name", new StringBody("Name"));
entity.addPart("type", new StringBody("Type1"));
post.setEntity(entity);
HttpResponse response = httpClient.execute(post);
int status = response.getStatusLine().getStatusCode();
...(略)
String postUrl = "http://www.sample.com/post.php";
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(postUrl);
MultipartEntity entity = new MultipartEntity();
try {
File file = new File(imagePath);
entity.addPart("image", new FileBody(file.getAbsoluteFile()));
post.setEntity(entity);
HttpResponse response = httpClient.execute(post);
int status = response.getStatusLine().getStatusCode();
...(略)
//ギャラリーの画像を選択したら
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
isOnLoading = true;
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_PICK_CONTACT) {
if (data != null) {
imageUri = data.getData();
Thread thr = new Thread(reqUpload);
thr.start();
}
}
}
}
//画像をPOSTする
private Runnable reqUpload = new Runnable() {
@Override
public void run () {
String resp = null;
String postUrl = "http://www.sample.com/post.php";
InputStream inputStream = getContentResolver().openInputStream(imageUri);
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(postUrl);
MultipartEntity entity = new MultipartEntity();
try {
InputStreamBody streamBody = new InputStreamBody(inputStream, "imagename");
entity.addPart("image", streamBody);
post.setEntity(entity);
HttpResponse response = httpClient.execute(post);
int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_OK){
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
response.getEntity().writeTo(oStream);
resp = oStream.toString();
} else {
Log.v("ERR","response status:" + String.valueOf(status));
}
} catch(IOException e) {
Log.v("ERR","msg:" + e.getMessage());
}
}
};