[英]php can't receive request from C# webrequest when post data length more than 8K
I am trying to send base64 encoded data through C# WebRequest
to php script. 我正在尝试通过C# WebRequest
将base64编码的数据发送到php脚本。 Then I receive sent data by file_get_contents("php://input")
, when data length is lower than 8 KBs the php code is executed, otherwise it can't be executed. 然后,我通过file_get_contents("php://input")
接收发送的数据,当数据长度小于8 KB时,将执行php代码,否则将无法执行。 In the other hand php didn't receive the request. 另一方面,php没有收到请求。
the code C#: 代码C#:
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
// postData is Base64_encoded
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseData = reader.ReadToEnd();
responseData = SecurityUtils.DecryptUrlData(responseData);
reader.Close();
dataStream.Close();
response.Close();
return responseData;
Could any one help? 有谁可以帮忙吗?
The below is incorrect (mea culpa). 以下是不正确的(Mea culpa)。 You cannot use enctype=multipart/form-data with php://input. 您不能通过php:// input使用enctype = multipart / form-data。 See here 看这里
Perhaps you can post your PHP code into your question as well? 也许您也可以将PHP代码发布到您的问题中?
Make sure that when you POST from the c# app to your PHP app that you set the enctype to multipart/form-data. 确保从c#应用程序发布到PHP应用程序时,将enctype设置为multipart / form-data。
Explanaition 解释
Are you using application/x-www-form-urlencoded or multipart/form-data? 您使用的是application / x-www-form-urlencoded还是multipart / form-data? There is a good explanation of the differenes here: application/x-www-form-urlencoded or multipart/form-data? 这里有一个很好的关于区别的解释: application / x-www-form-urlencoded或multipart / form-data?
According to the link above, posting data in the application/x-form-urlencoded format will put the body into the URL. 根据上面的链接,以application / x-form-urlencoded格式发布数据会将正文放入URL。 Many servers and languages (PHP, Apache) will cut off or throw errors when the URL is greater than 8K. URL大于8K时,许多服务器和语言(PHP,Apache)将切断或抛出错误。 See SO question: What is the maximum length for a URL? 看到这样的问题: URL的最大长度是多少?
Change the content type for the request 更改请求的内容类型
request.ContentType = "text/plain"; request.ContentType =“文本/纯文本”;
Check out php.ini´s post_max_size on the server side 退房php.ini's post_max_size要在服务器端
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.