masroore / CurlSharp

CurlSharp - .Net binding and object-oriented wrapper for libcurl.
BSD 3-Clause "New" or "Revised" License
182 stars 71 forks source link

Using curlsharp for veracode #4

Closed devendert closed 9 years ago

devendert commented 9 years ago

First of all my apologies; This is not an issue.

I am trying to execute veracode api using curlSharp library. Manually I can execute the command as below. curl --compressed -u [veracodeuser]:[mypassword] https://analysiscenter.veracode.com/api/4.0/getapplist.do -F 'include_user_info=true'

using (var easy = new CurlEasy()) { easy.UserPwd = "Password" easy.AutoReferer = true; easy.FollowLocation = true; easy.Url = textBoxUrl.Text.Trim(); easy.WriteFunction = OnWriteData; easy.Perform(); }

I couldn't figure out how to pass username and --compressed -F options. Could you please let me know if I can accomplish this with CurlSharp.

I appreciate your response.

masroore commented 9 years ago

@devendert First of all my apologies for late reply.

To enable compressed transfer, use the following code to set the Accept-Encoding: header:

easy.SetOpt(CurlOption.Encoding, "gzip");

Make sure to use a libcurl DLL which was built with ZLIB support. (The DLLs provided with curlsharp should be fine.)

As for authentication, the UserPwd property should be populated with username and password separated by colon:

easy.UserPwd = "username:password";

As for providing HTTP form data, please see the EasyPost sample project. More specifically, refer to the TEST 3 CurlEasy HttpPost section to see how to construct and use HTTP multi-part form data. If you simply need to transmit some raw POST data, you may use the PostFields property (see the TEST 2 CurlEasy PostFields section of the same project) It seems you may not need to the complicated CurlHttpMultiPartForm object for veracode.com...

easy.Post = true;
var postData = "include_user_info=true";
easy.PostFields = postData;
easy.PostFieldSize = postData.Length;
easy.Perform();

Hope this helps.

PS: I couldn't verify the code snippets. Veracode.com is returning some exception at the moment.