简体   繁体   English

Android / Java发送http帖子请求,其字符未重新格式化为UTF-8

[英]Android/Java Send a http post request with chars not reformatted as UTF-8

In an Android app I need to use a http post request to talk to a D-Link W215. 在Android应用程序中,我需要使用http发布请求来与D-Link W215对话。 I'm basically making a java version o fthe code found here: http://www.devttys0.com/2014/05/hacking-the-d-link-dsp-w215-smart-plug/ . 我基本上是在这里找到的代码的Java版本: http : //www.devttys0.com/2014/05/hacking-the-d-link-dsp-w215-smart-plug/ The problem is that one of the bytes I need to send is 0xAC and when it is sent over the network through java, it is received as unicode character \\00ac which are hex characters 0xC2 0xAC. 问题是我需要发送的字节之一是0xAC,当它通过Java通过网络发送时,它以Unicode字符\\ 00ac的形式接收,即十六进制字符0xC2 0xAC。 Is there a way to have byte 0xAC actually sent. 有没有一种方法可以实际发送字节0xAC。 Thanks. 谢谢。

Edit: I also have confirmed that the problem is when the bytes are sent as the data is correct when I check it before I send it. 编辑:我也已经确认问题出在发送字节时,因为在发送之前检查数据时数据是正确的。

Use the following code. 使用以下代码。

byte[] message = {0xAC};
Socket socket = ...
DataOutputStream dOut = new DataOutputStream(socket.getOutputStream());
dOut.write(message);   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM