HttpWebRequest 文件上传问题

发布于 2024-07-30 17:50:04 字数 917 浏览 3 评论 0原文

以下代码不起作用..

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘过的浮云 2024-08-06 17:50:04

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 your Main 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 a ManualResetEvent used by the Main method to wait until the callback signals completion.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文