using cUrl from c# - c#

I am trying to connect to clarify photo tagging service using c#. unfortunately they do not have a client api and I need to send cURL requests
The company website display the following code
curl "https://api.clarifai.com/v1/tag/" \
-X POST -F "encoded_data=#/Users/USER/my_image.jpeg" \
-H "Authorization: Bearer {access_token}"
I have tried different options with no luck
Is there a simple wrapper that I can use (that support the –x and –h options)
Or even better a code sample on how to approach this issue
Many thanks in advance

I believe, that Process.Start() suites your needs.

Related

How to POST using httpwebrequest when I need to authenticate and in curl the authentication is done with "username:pass#website.com"?

In brief, in curl I can send post like this:
curl -X POST http://admin:admin#website.com/scriptText -F 'data here'
So in C# what header or method should I use to mimic this? Is this just basic auth? It doesn't seem to be since when i open the website it uses classic php like post/cookie method to keep track.
I have a method in C# which lets me log in and keeps me there with cookie but after this i can only use downloadstring() method to GET and not post a "forbidden" data?

C#.Net :How to read data on web api posted using curl

How to read data "user_token" in WebAPI posted using curl command.
curl.exe "https://ssl.check.allin.net/api/Authenication" -d "user_token=3ff8c483-6c10-446d-a7b2-595b9d573d1f,content-length:1025" -v POST
I'm not able to find "user_token" in postdata, headers, querystring. How to access data posted . Can anyone please help me on this.
Thanks in Advance!!

Run a curl request in c#

I want to run a curl request given as
curl --data-binary #"/path/to/my.pdf" -H "Content-Type: application/pdf" -L "http://pdfx.cs.man.ac.uk"
This request simply sends a PDF file to http://pdfx.cs.man.ac.uk and in response this site return a XML file.
How it can be done in C#?
If I understand correctly, you want to reproduce form POST action in C#. One way is to use HttpClient from this package (.NET 4.0) or directly if working in .NET 4.5+.
A fully working example can be found here. Basically you have to:
you initialize the http client
initialize form data
post the data
wait for the response
You can also set the content type of posted content (in your case application/pdf), by following the provided answer from this question.

Attlassian Confluence creating a page

At the Moment, my Task is to automate some processes in our Company. One of them is to automaticilly creating pages on our Knowledgebase from Attlassian Confluence.
Normally I'm a .Net developer and I'm not familiar with REST API's. So I've read the documentation and that gave me the following line to create a new page:
curl -u admin:admin -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"new page","space":{"key":"TST"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}' http://localhost:8080/confluence/rest/api/content/
My Problem is, that I don't know, how to do this in C#.
I don't have a code example because I've done this via PowerShell and the ConfluencePS module. However, much of it can be done leveraging the .Net Framework.
In case it's useful to you, I suggest you familiarize yourself with the following - some of it depending on your .Net Framework version (e.g., 4.5+):
Basic Authentication (and Base64 encoding).
JavaScript Object Notation (JSON).
System.Net.Http.Httpclient.
System.Net.NetworkCredential.
System.Net.Http.HttpClientHandler.
And, a word of warning! When dealing with the Confluence RESTful API documentation make certain the documentation is for your specific Confluence version. Sounds obvious but it can be difficult to line the two up correctly.

Watson dialog cURL conversation post request not passing form data

When making a post cURL request as below to try and continue a created conversation watson instead returns a new conversation.
curl -u "USERNAME":"PASSWORD" -X POST --form conversation_id=CONVOID --form client_id=CLIENTID --form input="What type of toppings do you have?" "https://gateway.watsonplatform.net/dialog/api/v1/dialogs/DIALOGID/conversation"
If i use the below cURL it works fine.
curl -u "USERNAME":"PASSWORD" --data "conversation_id=CONVOID&client_id=CLIENTID&input=What type of toppings do you have?" https://gateway.watsonplatform.net/dialog/api/v1/dialogs/DIALOGID/conversation
My issue being that now when trying to write a c# wrapper i'm running in to the same issue that POST requests fail to transmit their form data correctly.
What's going on ?
I either need a c# MVC equivalent to the "--data" formatting. ( currently using HttpClient.PostAsync) or to figure out what is exactly wrong with using post requests to continue conversations.
As far as i can tell i am replicating the post request in c# correctly so i don't think there are two issues. ( just one post request issue, not a cURL issue then a C# implementation issue.)
For what it's worth i have left the commands in the format i submitted them, only replacing sensitive values with BLOCKCAPITALS. If it looks like i've missed a quotation mark or curly bracket , it's because i have and may be the cause of the issue.
The service expects an application/x-www-form-urlencoded POST request
To do that in curl you need to use the -d parameter:
curl -u "USERNAME":"PASSWORD" -X POST
-d conversation_id=CONVOID
-d client_id=CLIENTID
-d input="What type of toppings do you have?"
"https://gateway.watsonplatform.net/dialog/api/v1/dialogs/DIALOGID/conversation"
-d, --data
(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.
Curl documentation

Categories

Resources