这是客户端代码(C#):
string boundary = "--ABC";
try
{
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "multipart/form-data;boundary="+boundary;
using (var requestStream = request.GetRequestStream())
using (var writer = new StreamWriter(requestStream))
{
writer.WriteLine(boundary);
writer.WriteLine("Content-Disposition: form-data; name=\"data\"");
writer.WriteLine();
writer.WriteLine("abcdefg");
writer.WriteLine(boundary + "--");
writer.Flush();
}
string responseData = string.Empty;
using (var response = request.GetResponse())
using (var responseStream = response.GetResponseStream())
using (var reader = new StreamReader(responseStream))
{
responseData=reader.ReadToEnd();
}
这是服务器代码(php):
print file_get_contents("php://input");
或者:
print $_POST["data"];
或者:
print $http_raw_post_data;
或者:
$fp=fopen("php://output","rb");
$contents=fread($fp,5);
fclose($fp);
print $contents;
这些代码都不起作用,全部打印为空。
有人可以帮忙吗?