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?
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!!
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.
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.
I'm rather new to sending/receiving over networks/sockets/network streams and so on.
I'm making an IRC program that can communicate with Twitch.tv. They have an API, and they have examples of all sorts of requests you would use to get different kinds of information.
https://github.com/justintv/Twitch-API/tree/master/v3_resources
One example of their requests is this:
curl -H 'Accept: application/vnd.twitchtv.v3+json' \
-X GET https://api.twitch.tv/kraken/chat/kraken_test_user
I have tried to do some research on requests, and I sort of understand some, but for the most part I could not find any resources that help make it click for me.
In the above example, what are the important parts of that request? curl? -H? Is that one big command, or is it two commands separated by the \ at the end of the first line?
Then, the biggest question, how to send requests like the one above using C#?
EDIT 1:
I also know that I will be getting responses in JSON. Is there anything built in that assists with receiving/parsing JSON?
And also using PUT to change some JSON? (some things in the API allow PUT).
For the first bit of the question, you asked what are the important parts
It has an accept header of application/vnd.twitchtv.v3+json
It is a GET request
The api url: https://api.twitch.tv/kraken/chat/kraken_test_user
This request in c# could look like the following (could because there is more than one way to do it)
private async Task<object> GetRequest(string url)
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.twitchtv.v3+json"));
var response = await httpClient.GetAsync(url);
var contents = await response.Content.ReadAsStringAsync();
return contents;
}
Note that the files in the link you posted are to Mark Down files that Google describes as:
MD, or markdown document is a text file created using one of several possible dialects of the Markdown language. MD files use plain text formatting but includes inline text symbols that define how to format the text, and is designed for authoring plain text documentation that can be easily converted to HTML.
curl -H 'Accept: application/vnd.twitchtv.v3+json' \
-X GET https://api.twitch.tv/kraken/chat/kraken_test_user
http://curl.haxx.se/docs/manpage.html explains what the curl command is that then has 2 switches, H and X. where quoting the link:
-H, --header
(HTTP) Extra header to include in the request when sending HTTP to a
server. You may specify any number of extra headers. Note that if you
should add a custom header that has the same name as one of the
internal ones curl would use, your externally set header will be used
instead of the internal one. This allows you to make even trickier
stuff than curl would normally do. You should not replace internally
set headers without knowing perfectly well what you're doing. Remove
an internal header by giving a replacement without content on the
right side of the colon, as in: -H "Host:". If you send the custom
header with no-value then its header must be terminated with a
semicolon, such as -H "X-Custom-Header;" to send "X-Custom-Header:".
curl will make sure that each header you add/replace is sent with the
proper end-of-line marker, you should thus not add that as a part of
the header content: do not add newlines or carriage returns, they will
only mess things up for you.
See also the -A, --user-agent and -e, --referer options.
Starting in 7.37.0, you need --proxy-header to send custom headers
intended for a proxy.
Example:
# curl -H "X-First-Name: Joe" http://192.168.0.1/
WARNING: headers set with this option will be set in all requests -
even after redirects are followed, like when told with -L, --location.
This can lead to the header being sent to other hosts than the
original host, so sensitive headers should be used with caution
combined with following redirects.
This option can be used multiple times to add/replace/remove multiple
headers.
The "\" makes the next line be added to the first line.
-X, --request
(HTTP) Specifies a custom request method to use when communicating
with the HTTP server. The specified request method will be used
instead of the method otherwise used (which defaults to GET). Read the
HTTP 1.1 specification for details and explanations. Common additional
HTTP requests include PUT and DELETE, but related technologies like
WebDAV offers PROPFIND, COPY, MOVE and more.
Normally you don't need this option. All sorts of GET, HEAD, POST and
PUT requests are rather invoked by using dedicated command line
options.
This option only changes the actual word used in the HTTP request, it
does not alter the way curl behaves. So for example if you want to
make a proper HEAD request, using -X HEAD will not suffice. You need
to use the -I, --head option.
The method string you set with -X will be used for all requests, which
if you for example use -L, --location may cause unintended
side-effects when curl doesn't change request method according to the
HTTP 30x response codes - and similar.
(FTP) Specifies a custom FTP command to use instead of LIST when doing
file lists with FTP.
(POP3) Specifies a custom POP3 command to use instead of LIST or RETR.
(Added in 7.26.0)
(IMAP) Specifies a custom IMAP command to use instead of LIST. (Added
in 7.30.0)
(SMTP) Specifies a custom SMTP command to use instead of HELP or VRFY.
(Added in 7.34.0)
If this option is used several times, the last one will be used.
In C#, there is a WebRequest class that https://msdn.microsoft.com/en-CA/library/456dfw4f(v=vs.110).aspx has a good example of how to use to get data from a given URL.
As for handling JSON, please look into http://www.newtonsoft.com/json which is a rather common library used for parsing JSON responses. PUT would be the HTTP verb like GET or POST used to tell the server how to process a request. I'd suggest in the future be careful about posting a rather broad set of questions here as I could see this being something that a class could spend an hour covering somewhere that I doubt your intention is getting someone else to do your homework, right?