我想以字节格式将字符串数据 "" 发送到 android 应用程序中的服务器。我使用 HttpClient 但我认为它不是正确的方法,请帮助我如何做到这一点?
在 .net 的情况下,我想要 java 中的类似代码。
string boundary = Guid.NewGuid().ToString();
HttpWebRequest request = HttpWebRequest.Create(url)
as HttpWebRequest;
request.Method = "POST";
//request.ContentType = "application/json";
request.PreAuthenticate = true;
byte[] fulldata = Encoding.UTF8.GetBytes(data);
request.ContentLength = fulldata.Length;
using (Stream sw = request.GetRequestStream())
{
sw.Write(fulldata, 0, fulldata.Length);
}