将pdf文件上传到服务器上HttpWebRequest [英] Upload pdf file on server wit HttpWebRequest
本文介绍了将pdf文件上传到服务器上HttpWebRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在服务器上上传pdf文件时遇到问题.我无法使用webclient.upload,因为我使用的是Compatct Framework 3.5.
要上传文件,我使用http POST消息,但是有一个内部服务器错误
i''ve a problem with the upload of pdf file on a server.I can''t use webclient.upload because i work on compatct framework 3.5.
To upload the file i use http POST message but there is a interna server error
private void UploadFilesToRemoteUrl(){
string post_data = this.openFileDialog1.FileName;
// this is where we will send it
string uri = this.indirizzo + "servletUpload/controllerFiles";
// create a request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version11;
request.Method = "POST";
// turn our request string into a byte stream
byte[] postBytes = Encoding.ASCII.GetBytes(post_data);
// this is important - make sure you specify type this way
request.ContentType = "application/octet-stream";
request.ContentLength = postBytes.Length;
request.TransferEncoding = "bynary";
Stream requestStream = request.GetRequestStream();
// now send it
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
// grab te response and print it out to the console along with the status code
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
MessageBox.Show(new StreamReader(response.GetResponseStream()).ReadToEnd());
MessageBox.Show(response.StatusCode.ToString());
}
我需要帮助
非常感谢
I need help
Thanks a lot
推荐答案
David,文件有多大?
没有看到错误,很可能是您尝试上传的文件超出了允许的范围(默认情况下).
服务器正在运行什么,并且要发布到什么位置?您看到错误了吗?在服务器日志中如何?
干杯.
David, how big is the file?
Without seeing the error, it''s likely that you are trying to upload a bigger file than is allowed (by default).
What is the server running, and what are you POSTing to? Is there an error that you see? How about in the server logs?
Cheers.
这篇关于将pdf文件上传到服务器上HttpWebRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文