0

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#?

  • What did you try to run it, you can just run that - what specifically did you want to achieve? – BugFinder Nov 30 '16 at 15:00
  • You've got to create a process and execute the command from within the process. Check out http://askubuntu.com/questions/506985/c-opening-the-terminal-process-and-pass-commands – Blake Neal Nov 30 '16 at 15:02
  • `Process.Start` maybe? – Biesi Nov 30 '16 at 15:02
  • 1
    Have you looked at the `WebRequest`, `WebClient`, or `HttpClient` classes in .NET? – Ian Mercer Nov 30 '16 at 15:03
  • I would echo the above comment. .NET has its own built-in classes for making HTTP requests. Using an external tool like curl is unnecessary and overcomplicates things. – ADyson Nov 30 '16 at 15:05
  • @BugFinder I'll manipulate the returned XML file further for my own project. – Shahbaz Ahmad Sahi Nov 30 '16 at 15:06
  • 1
    @ShahbazAhmadSahi that didnt answer what I said one tiny tiny bit – BugFinder Nov 30 '16 at 15:08
  • @IanMercer how can I send the web request, that contains the PDF file with it. Any reference? – Shahbaz Ahmad Sahi Nov 30 '16 at 15:08
  • @ShahbazAhmadSahi "how can I send the web request that contains the PDF file...?" https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=C%23+send+web+request+pdf+file here are lots of references. – ADyson Nov 30 '16 at 16:43

1 Answers1

1

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.

Community
  • 1
  • 1
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164