次のコードがあります。
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.cache.HeaderConstants;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.HttpClientBuilder;
public class MyMain {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File file1 = new File("C:\\Users\\Avner.MARKETOLOGY\\Desktop\\a.jpg");
URI uri;
try {
uri = new URI("http://www.amaya365.com/kinderPhp/uploadFiles.php");
//uri = new URI("http://www.amaya365.com/kinderPhp/uploadFiles.php");
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(uri);
post.getEntity();
// Http Headers
//post.addHeader("Accept", "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2");
post.addHeader("Connection", "keep-alive");
//Charset chars = Charset.forName("UTF-8");
MultipartEntityBuilder multiEntity = MultipartEntityBuilder.create();
multiEntity.addPart("file", new FileBody(file1));
//multiEntity.addPart("file2", new FileBody(file2));
multiEntity.addTextBody("classid", "55555");
multiEntity.addTextBody("albumid", "111");
//multiEntity.addBinaryBody("classid",ptext);
// Credentials
/*multiEntity.addPart("username", new StringBody(ServerData.username));
multiEntity.addPart("password", new StringBody(ServerData.password));*/
HttpEntity httpEntity = multiEntity.build();
post.setEntity(httpEntity);
HttpResponse response = client.execute(post);
//HttpEntity entity = response.getEntity();
//if (entity != null) {
InputStream is = response.getEntity().getContent();
/*int i = (int)response.getEntity().getContentLength();
System.out.println(i);*/
byte[] b = new byte[is.available()];
String str = null;
while(is.read(b) > -1){
str += new String(b);
}
System.out.println(str);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 200) {
System.out.println("upload completed succefully "+statusCode);
}else{
//try again
}
//}
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
albumid と classid が number または English に設定されている限り、問題なく動作します。ヘブライチャータラーを使用すると、???? 投稿リクエストで。
投稿リクエストでヘブライ文字を送信するにはどうすればよいですか?
thx、アヴナー。