5

文字列「Приветмир!」を送ってみます

String link = POST_URL;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(link);
String xml ="Привет мир";
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("file", xml));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);

そして、phpスクリプトで保存します。

if(!empty($_REQUEST['file'])){
$fp = fopen("C:\\windows\\temp\\1.xml", "w");
$mytext =$_POST["file"];
$test = fwrite($fp, $mytext); 
fclose($fp); 

しかし、私は?????? ????? Webサーバーで、utfエンコーディングを使用してファイルを再度開いてみましたが、役に立ちません。どうすれば解決できますか。

4

2 に答える 2

17

StringEntityのUTF-8への文字セット。これらの行はトリックを行います:

 httpPost.setEntity(new StringEntity(body, HTTP.UTF_8));
于 2013-03-10T12:07:06.183 に答える
4

これは私のために働いた:

HttpPost httpPost = new HttpPost("http://someurl.com");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair, HTTP.UTF_8));
于 2014-07-21T14:02:40.110 に答える