Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 构建一个post-request-wish-Hebrew数据_Java_Post - Fatal编程技术网

Java 构建一个post-request-wish-Hebrew数据

Java 构建一个post-request-wish-Hebrew数据,java,post,Java,Post,我有以下代码: 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.

我有以下代码:

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,就可以正常工作。 当我使用希伯来语租船人时,我得到了????根据邮政要求

我应该怎么做才能通过post请求发送希伯来文字符

thx,
Avner。

在使用
addTextBody
函数时,您可能应该使用
ContentType
参数。

不仅希伯来语而且日语都是乱码。在我的例子中,我使用addTextBody(),它也会崩溃日语字符。