C# 为什么发布base64编码的图像时发送空值?
我想使用POST方法并使用以下代码将base64编码的图像发送到远程服务器。 但内容在长度为零的远程服务器中为空。 怎么了?我对base64的编码是否错误C# 为什么发布base64编码的图像时发送空值?,c#,C#,我想使用POST方法并使用以下代码将base64编码的图像发送到远程服务器。 但内容在长度为零的远程服务器中为空。 怎么了?我对base64的编码是否错误 string Base64; byte[] by; by=File.ReadAllBytes(Server.MapPath("Sunset.jpg")); Base64 = Convert.ToBase64String(by); Server.UrlEnc
string Base64;
byte[] by;
by=File.ReadAllBytes(Server.MapPath("Sunset.jpg"));
Base64 = Convert.ToBase64String(by);
Server.UrlEncode(Base64);
Automation.Sending(Base64);
Automation Class:
sending method:
public static void sending(string Base)
{
String s;
string pass ="xx";
StringBuilder postData = new StringBuilder(1000);
postData = new StringBuilder(100);
postData.Append("module=Scan&action=addPict");
postData.Append("&user=xxx");
postData.Append("&pass=" + pass);
postData.Append("&Id=");
postData.Append("660913");
postData.Append("&content =" + Base);// Base64 encoded file
s = doRequest(postData);
}
DoRequest method:
private static String doRequest(StringBuilder postData)
{
byte[] dataArray = Encoding.UTF8.GetBytes(postData.ToString());
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create("http://10.10.2.97/officeas/Runtime/process.php?");
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";
httpRequest.ContentLength = dataArray.Length;
Stream requestStream = httpRequest.GetRequestStream();
requestStream.Write(dataArray, 0, dataArray.Length);
requestStream.Flush();
requestStream.Close();
HttpWebResponse webResponse = (HttpWebResponse)httpRequest.GetResponse();
if (httpRequest.HaveResponse == true)
{
Stream responseStream = webResponse.GetResponseStream();
StreamReader responseReader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
String responseString = responseReader.ReadToEnd();
return responseString;
}
else
Console.Write("no response");
return "";
}
与pcap.net有什么关系?正在删除标记。是否为空?还是长度为零?这些事情是不同的。另外,如果你用小提琴手检查它,它看起来还好吗?基地有多大?我的意思是:在代码中,不仅仅是文件大小/这可能是映射路径错误的问题吗?Base64在我的程序中是94920字节,但在远程服务器中没有接收到任何东西,它是null。谢谢大家。我在&content和=。我把它拿走了,我的问题解决了。postData.Append&content=+Base