(转)How to use HttpSendRequestEx with password-protected URLs
来源:互联网 发布:淘宝模特拍照动作技巧 编辑:程序博客网 时间:2024/05/18 03:35
http://support.microsoft.com/default.aspx?scid=kb;en-us;194700
This article was previously published under Q194700
This is the usual sequence of APIs used with HttpSendRequest:
InternetConnect () HttpOpenRequest () HttpSendRequestEx () HttpEndRequest ()
Method 1If the user name and password are known before sending the request (that is, they don't have to be dynamically entered by the user), then user name and password can be supplied directly to the InternetConnect API. However, unlike HttpSendRequest, HttpSendRequestEx will not resubmit a request on its own after receiving the "401 Access Denied" status code from the server. Therefore, HttpEndRequest will fail with an ERROR_INTERNET_FORCE_RETRY error. This error message from HttpEndRequest indicates that the application must go back to HttpSendRequestEx and send all the buffers with InternetWriteFile again.
Method 2If it is not possible to supply credentials in the InternetConnect API, then you must use the following steps: Similarly to HttpSendRequest, the status code of the request may be determined by calling HttpQueryInfo (hRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG). With HttpSendRequestEx, HttpQueryInfo must be called after HttpEndRequest, not after HttpSendRequestEx. Valid credentials can be entered either with InternetErrorDlg() or by calling InternetSetOption with INTERNET_OPTION_USERNAME and INTERNET_OPTION_PASSWORD options. Similarly to method 1, the application should go back toHttpSendRequestEx. Both of the methods above have a serious drawback: Because HttpSendRequestEx is used to send large amounts of data, resubmitting the entire data upon receiving the ERROR_INTERNET_FORCE_RETRY error or the 401 status code may waste network bandwidth and time. Method 3 is the preferred method of handling user authentication with HttpSendRequestEx:
Method 3This method involves sending an auxiliary request for the URL via HttpSendRequest. Note that HttpSendRequestEx should be called on the same handle as HttpSendRequest. This will ensure that the request sent by HttpSendRequestEx will be sent over the connection authenticated by the first call to HttpSendRequest. Reusing the connection (using "Keep-Alive" connection) is necessary for NTLM (NT LAN manager authentication) support. To preserve bandwidth and time, neither request nor reply should have large amounts of data. The best way to accomplish this is to send the same type of request with HttpSendRequest as HttpSendRequestEx, but with the 0 content length.The following steps show how to use an auxiliary request. It assumes that large amounts of data need to be POSTed to /Scripts/Poster.exe URL:
Performing all the authentication in HEAD request causes WinInet to create an appropriate authorization header that is sent with a large request submitted by HttpSendRequestEx. ====================================结论: 解决方案一:1.HttpOpenRequest 里面要 INTERNET_FLAG_KEEP_CONNECTION,http版本:HTTP/1.1 2.要把windows集成认证的用户名、密码,填入到InternetConnectr的第四、五个参数中去3.先用HttpSendRequest 试探性地访问资源,并用InternetReadFile 读完返回结果要把这次的hRequest 关掉,再打开一个hRequest(否则上传时Content-Lenth为0),或者在第四步自己把Content-Length设置好4.使用HttpSendRequestEx -InternetWriteFile-HttpEndRequest 组合上传文件,如果最后返回ERROR_INTERNET_FORCE_RETRY则这步重新来过。解决方案二(测试通过):1.HttpOpenRequest 里面要 INTERNET_FLAG_KEEP_CONNECTION,http版本:HTTP/1.12.使用HttpSendRequestEx -InternetWriteFile-HttpEndRequest 组合上传文件,如果最后返回ERROR_INTERNET_FORCE_RETRY则这步重新来。
转自:http://blog.163.com/jianlizhao@126/blog/static/1732511632011576192085/
- (转)How to use HttpSendRequestEx with password-protected URLs
- rc : how to use HttpSendRequestEx
- (转)How to use MySQL with 3D Studio Max
- How to use gnu readline to implement "reset password".
- How To Use Linux epoll with Python
- How to use Trace2UML together with Doxygen
- How To Use Linux epoll with Python
- How to use Blocks with iOS
- how to use linux epoll with c
- How to use Django with uWSGI
- How to use passwords securely with wget
- How To Use Linux epoll with Python
- How to use http cookies with Qt
- how to use Wordnet with Java?
- How to use Django with mod_wsgi.
- How to use http cookies with Qt
- How To Use Linux epoll with Python
- How to use GitHub with Android Studio
- HDU 1018 Big Number
- webservice的demo
- C++中#include<iostream.h>和#include<iostream>
- 分享45款高质量的免费(X)HTML/CSS模板
- UVa10596 Morning Walk
- (转)How to use HttpSendRequestEx with password-protected URLs
- 添加和获取XData扩展数据
- sg算法吧...
- OK6410开发板开发环境搭建-NFS文件启动和使用dnw2烧写镜像文件
- UrlDownloadtoFile文件下载,进度条,下载暂停,停止的简单实现
- C语言打印十进制数
- 内核日志及printk结构浅析
- JSON总结及其解析(for Java) .
- 模版