本文介绍了CURL不编码UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Windows 10 curl 7.52.1
当我尝试将 POST 数据发送到WEBSERVICE时, curl 不会将字符编码为 UTF- 8 (我需要显示 pt-BR 字符,例如àáçÇãõ等)



是的,我已经检查了,但没有成功。



如果我将编码页面设置为 chcp 65001 ,则错误仍然存​​在。
更改为 chcp 1252 部分解决了问题。



看,如果我提示echoAdministração>> test.txt 没有任何 chcp 更改,我得到管理员‡ÆÆ



更改为 chcp 65001 后,我Administração



更改为 chcp 1252 后我终于Administração



但是使用卷曲,没有任何变化。



我试过设置标题 content-type ,没有幸运:

  curl -X POST -hContent-Type:text / plain; charset = UTF-8 --data-asciiname =Administraçãohttp //:localhost:8084 / ws / departments 

我得到以下输出:



{holder:{entities:[{name:Administraï¿ ½ï¿½o,dateReg:2016年12月29日下午2:05:33},sm:{}},消息:{text:},状态: - 1}



当我运行时,我还检查了 WS 它正在接受字符编码(在 JQuery 中):

  $。ajax({
url:http:// localhost:8084 / ws / departments,
type :POST,
data:{name:Administração},
success:function(data,textStatus,xhr){
console.log(data);
}
});

我得到预期的输出:



{holder:{entities:[{name:Administração,dateReg:2016年12月29日下午2:03:17},sm :{}},消息:{text:},状态: - 1}



拜托,你能帮助我吗?



提前致谢。



UPDATE



正如@Dekel所建议的那样,我还尝试使用外部文件作为数据副本( test.txt name =Administração):

  curl -i -X POST  - HContent-Type:text / plain; charset = UTF-8--data-binary@ test.txthttp:// localhost:8084 / ws / departments 

我仍然得到这个不寻常的输出:

  ** {持有人:{实体:[{name:Administra��o,dateReg:2016年12月29日下午2:41:27},sm:{}} ,message:{text:},status: -  1} ** 

更新2



@Phylogenesis建议使用 charset = ISO-8859-1 。我注意到,即使返回Administração结果,在服务器端进行狭窄检查,WS正在接收确切的字母,在这种情况下ç

解决方案

在与@Dekel讨论后,来自@Phylogenesis的建议我可以部分地解决问题,但是有效。有两种方式:




  • charset = ISO-8859-1

  • 编码文件并作为二进制数据发送



服务器可以使用<$接收正确的字母C $ C>字符集= ISO-8859-1 。甚至来自服务器的响应数据也显示不正确。



我使用: curl -i -X POST -HContent-Type:text / plain; charset = ISO-8859-1 - data-asciiname =Administraçãohttp:// localhost:8084 / ws / departments



第二种方法是编码包含要POST的所有内容的文件。我使用 Notepad ++>格式>转换为UTF-8(无BOM)



然后,提示: curl - i -X POST -HContent-Type:text / plain; charset = UTF-8--data-binary@ test.txthttp:// localhost:8084 / ws / departments


I'm using Windows 10 and curl 7.52.1.When I try to POST data to a WEBSERVICE, curl isn't encoding the characters to UTF-8 (I need to display pt-BR characters, like àáçÇãõ etc)

Yes, I have already checked this, no success.

If I set the encoding page to chcp 65001, the error persists.Changing to chcp 1252 solved the problem partially.

Look, if I prompt echo Administração >> test.txt without any chcp change, I get an Administra‡Æo.

After change to chcp 65001 I get Administração.

After change to chcp 1252 I finally get Administração.

But using curl, nothing change.

I've tried setting a header content-type, no lucky:

curl -X POST -h "Content-Type: text/plain; charset=UTF-8" --data-ascii "name=Administração" http//:localhost:8084/ws/departments

I get the following output:

{"holder":{"entities":[{"name":"Administra��o","dateReg":"Dec 29, 2016 2:05:33 PM"}],"sm":{}},"message":{"text":""},"status":-1}

I have also checked the WS it's accepting the characters encoding, when I run (in JQuery):

$.ajax({
     url:"http://localhost:8084/ws/departments",
     type:"POST",
     data: {name: "Administração"},
     success: function(data, textStatus, xhr){
       console.log(data);
     }
});

I get the output expected:

{"holder":{"entities":[{"name":"Administração","dateReg":"Dec 29, 2016 2:03:17 PM"}],"sm":{}},"message":{"text":""},"status":-1}

I don't know what else can I try to solve this.Please, could you guys help me?

Thanks in advance.

UPDATE

As suggested by @Dekel, I tried also using an external file as data-bynary (the content inside test.txt is name=Administração):

curl -i -X POST -H "Content-Type: text/plain; charset=UTF-8" --data-binary "@test.txt" http://localhost:8084/ws/departments

I still get this unusual output:

**{"holder":{"entities":[{"name":"Administra��o","dateReg":"Dec 29, 2016 2:41:27 PM"}],"sm":{}},"message":{"text":""},"status":-1}**

UPDATE 2

@Phylogenesis suggested to use charset=ISO-8859-1. I noticed that even returning Administração as result, checking narrowly in the server-side, the WS is receiving the exact letter, in this case ç.

解决方案

After a discussion with @Dekel and a suggestion coming from @Phylogenesis I could resolve the problem partially, but effectively. There are 2 ways:

  • charset=ISO-8859-1
  • encoding a file and sending as binary-data

The server could receive the correct letter using charset=ISO-8859-1. Even the response data from server showing incorrectly.

I use: curl -i -X POST -H "Content-Type: text/plain; charset=ISO-8859-1" --data-ascii "name=Administração" http://localhost:8084/ws/departments

The second way is encoding a file containing all the content you want to POST. I used Notepad++ > Format > Convert to UTF-8 (Without BOM).

Then, prompt: curl -i -X POST -H "Content-Type: text/plain; charset=UTF-8" --data-binary "@test.txt" http://localhost:8084/ws/departments.

这篇关于CURL不编码UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:36