简体   繁体   English

HTTP身份验证和文件以C结尾

[英]HTTP authentication and filesend in C

i have some parsed data in two files. 我在两个文件中有一些解析的数据。 i need to send these to a webserver of a website. 我需要将这些发送到网站的网络服务器。 i also need to be logged into the webserver first. 我还需要先登录到Web服务器。 i am new to this web interaction thing. 我是这个网络互动的新手。 i just need to know how might i go about doing this. 我只需要知道我该怎么做。 i am learning the libcurl library so i guess it can send standard HTTP POST messages. 我正在学习libcurl库,因此我想它可以发送标准的HTTP POST消息。 i will make a simple webserver to test it myself. 我将制作一个简单的Web服务器自己进行测试。 can anyone tell me what kind of interaction is needed. 谁能告诉我需要什么样的互动。 by that i mean how do i send the username and password information, know that i am logged in and then be send the files. 我的意思是说,我该如何发送用户名和密码信息,知道我已登录,然后发送文件。 may be some examples of Form Posts which i believe is what i shud be doing right now. 可能是Form Post的一些示例,我认为这是我现在应该做的事情。

Depending on the type of authentication being performed, the libcurl library may have functionality already built into it to support what you are trying to do. 根据执行的身份验证类型,libcurl库可能已经内置了功能以支持您尝试执行的操作。 Check out the curl_easy_setopt function--specifically the section dealing with authentication. 查看curl_easy_setopt函数,特别是有关身份验证的部分。

For basic authentication, you can do the following. 对于基本身份验证,您可以执行以下操作。

curl_easy_setopt( curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_easy_setopt( curl, CURLOPT_USERPWD, "username:password" );

You can use for example an old Wininet.dll ( http://msdn.microsoft.com/en-us/library/aa385473%28VS.85%29.aspx ) or more recent Winhttp.dll on the client side. 您可以在客户端使用例如较旧的Wininet.dll( http://msdn.microsoft.com/zh-cn/library/aa385473%28VS.85%29.aspx )或更新的Winhttp.dll。 The last one (WinHTTP) has two C/C++ API and COM Interface. 最后一个(WinHTTP)具有两个C / C ++ API和COM接口。 Moreover, in WinHTTP you have more Authentication options ( http://msdn.microsoft.com/en-us/library/aa383144%28VS.85%29.aspx ). 此外,在WinHTTP中,您还有更多的身份验证选项( http://msdn.microsoft.com/zh-cn/library/aa383144%28VS.85%29.aspx )。

On the other side old Wininet.dll has function like InternetWriteFile. 另一方面,旧的Wininet.dll具有类似于InternetWriteFile的功能。 In InternetConnect (Wininet.dll) you can give lpszUsername and lpszPassword. 在InternetConnect(Wininet.dll)中,您可以指定lpszUsername和lpszPassword。

In WinHTTP you should use WinHttpSetOption and WinHttpSetCredentials to give Username and password. 在WinHTTP中,应使用WinHttpSetOption和WinHttpSetCredentials来提供用户名和密码。

Search for both Wininet and WinHTTP and you will find enough Information to decide which one is better for your requirements. 搜索Wininet和WinHTTP,您将找到足够的信息来确定哪一个更适合您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM