HttpWebRequest 文件上传问题
以下代码不起作用..
WriteCallback 永远不会发生并检查 fiddler 并且
它也从不 POST 但执行 GET
私有无效上传(){
var ub = new UriBuilder(UploadUrl);
Debug.Text += "请求" + ub.Uri + "\n";
var webrequest = (HttpWebRequest)WebRequest.Create(ub.Uri);
webrequest.Method = "POST";
Debug.Text += "方法:" + webrequest.Method + "\n";
webrequest.BeginGetRequestStream(新 异步回调(WriteCallback), 网络请求);
Debug.Text += "webRequested\n";
}私有无效 WriteCallback(IAsyncResult 异步结果)
{
Debug.Text += "WriteCallback\n";
}
给我: 请求 http://localhost:22792/receiver.ashx?filename=Unsaved (1 ).AVI&StartByte=0&Complete=False
方法:POST
网络请求
The following code is not working..
The WriteCallback never happens and checking fiddler and also
it never POST but does a GET
private void Upload() {
var ub = new UriBuilder(UploadUrl);
Debug.Text += "Requesting " + ub.Uri + "\n";
var webrequest = (HttpWebRequest)WebRequest.Create(ub.Uri);
webrequest.Method = "POST";
Debug.Text += "Method : " + webrequest.Method + "\n";
webrequest.BeginGetRequestStream(new
AsyncCallback(WriteCallback),
webrequest);
Debug.Text += "webRequested\n";
}private void
WriteCallback(IAsyncResult
asynchronousResult)
{
Debug.Text += "WriteCallback\n";
}
gives me the :
Requesting http://localhost:22792/receiver.ashx?filename=Unsaved (1).AVI&StartByte=0&Complete=False
Method : POST
webRequested
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WriteCallback
中没有任何代码来指示您已完成事件处理。 因此,我假设您的 Main 函数或线程没有等待请求完成。 请参阅以下文档中的示例代码:特别是,查看 C# 示例并搜索
allDone
,它是Main
方法用于等待的ManualResetEvent
直到回调信号完成。You don't have any code in
WriteCallback
to indicate that you're done processing the event. So, I'm assuming yourMain
function or thread is not waiting for the request to be completed. Please see the sample code in the following documentation:In particular, look at the C# example and search for
allDone
which is aManualResetEvent
used by theMain
method to wait until the callback signals completion.