如何中止使用Wininet发送的请求? [英] How can I abort a request sent using wininet?

查看:49
本文介绍了如何中止使用Wininet发送的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MFC应用程序,用于将发布请求发送到相应的服务器.这是一个http请求,用于上传文件.

I have an MFC application in which I used to send a post request to the corresponding server. It is an http request, for uploading a file.

但是需要中止发送的请求.就像用户正在发送一个大文件,并且用户应该能够在请求完成之前取消该请求一样.

But there is a requirement to abort the request sent. Like if the user is sending a large file and user should be able to cancel the request before it is completed.

我正在使用Wininet API, HttpSendRequestEx InternetWriteFile HttpEndRequest .但是一旦请求发送完毕,除非请求完成或超时,否则我将无法中止请求.

I am using wininet apis, HttpSendRequestEx, InternetWriteFile and HttpEndRequest for this. but once the request is sent, I am not able to abort it in between unless the request is got completed or timed out.

任何人请提出一个取消处理或已发送请求的选项.

Anyone please suggest an option for canceling a processing or sent request.

我尝试了

I have tried closing the request handles, but still the request not gets aborted.

任何人都请帮忙.在此先感谢

Any one please help.. Thanks in Advance

推荐答案

从客户端的角度来看,只能使用 InternetCloseHandle 例程中止/断开当前操作.从客户端的角度来看,这将立即中止请求/操作,因此用户可以继续执行其他操作.

From a client aspect, you can only abort/disconnect from the current operation by using the InternetCloseHandle routine. This will instantly abort the request/operation from a client perspective, so the user can continue with another action.

但是,当数据已经发送到服务器时,这只会导致不返回响应!

But when the data has already been sent to the server, this will only result in not getting back a response!

正如Igor所说,一旦发送了完整的请求(数据)(此时客户端只是等待从服务器接收数据),就不能在服务器上中止处理.

As said by Igor, you cannot abort the processing at the server, as soon as the complete request (data) has been sent (at which point the client just waits to receive data from the server).

因此,您需要查看要在服务器上取消发送"请求或在服务器上还原文件的位置,方法是使用第一个响应从客户端向服务器发送新的删除"请求请求(此响应应包含有关添加的文件的信息,例如密钥).

So you need to look at the point where you want to cancel 'sending' the request or revert the file addition at the server by sending a new 'delete' request from the client to the server, using the response of the first request (this response should contain information about the added file - like a key).

这篇关于如何中止使用Wininet发送的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆